【问题标题】:CAKEPHP: Problems with filtersCAKEPHP:过滤器问题
【发布时间】:2012-06-17 10:45:05
【问题描述】:

我正在尝试对员工应用过滤器,以便仅在时间表表上显示他们。如果需要其他代码来帮助您帮助我,我将开始发布它。代码是filter.ctp

http://webdesign4.georgianc.on.ca/~100141468/comp2084/todo/employees

问题: http://webdesign4.georgianc.on.ca/~100141468/comp2084/todo/timesheets/filter/19

    <table>
<tr>
<th>ID</th><th>name</th><th>Hours</th><th>Employees</th><th>Edit</th>
</tr>

<? foreach($timesheets as $row): ?>
     <tr><td>
<?=$row['Timesheet']['id']?>
</td><td>
<?=$row['Timesheet']['hours']?>
</td><td>
<a href="../../employees/view/<?=$row['employee']['name']?>"><?=$row['employee']['name']?></a>
</td><td>
<a href="edit/<?=$row['Timesheet']['id']?>">Edit</a>
    </td></tr>
<? endforeach; ?>
</table>

<?
class TimesheetsController extends AppController {
    var $name = 'Timesheets';
    var $scaffold;  
    var $helpers = array('Number');

    function add() {

        //check if user loaded form for first time or had already loaded & is now posting
        if ($this->request->is('post')) {

            //save the data to the db
            if ($this->Timesheet->save($this->request->data)) {

                //Build message & add to session
                $this->Session->setFlash('Timesheet has been saved');

                //take user back to the index page
                $this->redirect(array('action'=>'index'));
            }
            //else save did not work
            else {
                $this->Session->setFlash('Unable to add Timesheet');            
            }
        }

        //populate the Employee list
        $this->loadModel('Employee');
        $this->set('Employees',$this->Employee->find('list',array('order'=> array('Employee.name'))));
        $this->set(compact('Employees'));       

        //populate the Employee list
        $this->loadModel('Client');
        $this->set('Clients',$this->Client->find('list',array('order'=> array('Client.name'))));
        $this->set(compact('Clients')); 
    }

        //create function to filter Timesheet list by selected Employee
        function filter($Employee_id) {
            $this->set('Timesheets',$this->Timesheet->findAllByEmployeeId($Employee_id));
        }
            //create function to filter Timesheet list by selected Employee
        function filter2($Client_id) {
            $this->set('Timesheets',$this->Timesheet->findAllByClientId($Client_id));
        }


}
?>

【问题讨论】:

    标签: cakephp filter


    【解决方案1】:

    您可能需要使用 $this-&gt;set('timesheets', $timesheets) 在控制器上设置变量 $timesheets

    【讨论】:

    • 我把我的控制器放在那里,你能找出我放的地方吗?我想我已经有了。
    • 哦,我明白了... php 变量区分大小写... 您正在设置时间表并尝试使用时间表
    • 所以它们都应该大写还是小写?
    • 这(技术上)无关紧要,但需要在 Controller 和 View 上完全相同。在这种情况下,您有一个以 Capital 开头,另一个以小写字母开头。根据 PHP 编码标准,我认为应该全部小写
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2011-08-04
    • 2010-09-20
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多