Thanks for you answer me.And I try the method you provided.I have
AppHelper.And I also change the __construct() in GridHelper.php ,but it
seems not work.
在 2012年7月5日星期四UTC+8下午4时14分18秒,Superidea写道:
>
> Hello,
>
> View is no more part of ClassRegistry.
>
> Better approach could be as below for you helper
>
> Do you have AppHelper.php and how it look like ?
> AppHelper should look like :
> //
> App::uses('Helper', 'View');
>
> /**
> * Application helper
> *
> * Add your application-wide methods in the class below, your helpers
> * will inherit them.
> *
> * @package app.View.Helper
> */
> class AppHelper extends Helper {
> }
> //
>
> And then do not forget to call the AppHelper construct in your Grid helper.
>
> function __construct(View $view, $settings = array()){
> parent::__construct($view, $settings);
> // Here you can use $view->viewVars blah blah
> }
>
>
> On Thu, Jul 5, 2012 at 9:20 AM, LiveJin <[email protected]> wrote:
>
>> I use the CakeGrid plugin,but I met some problems.
>>
>> *this is the error log:*
>> 2012-07-05 15:13:26 Error: Fatal Error (1): Call to a member function
>> element() on a non-object in
>> [G:\htdocs\cakedemo\app\Plugin\CakeGrid\View\Helper\GridHelper.php, line
>> 178]
>> 2012-07-05 15:13:26 Error: [FatalErrorException] Call to a member
>> function element() on a non-object
>> #0 G:\htdocs\cakedemo\lib\Cake\Error\ErrorHandler.php(162):
>> ErrorHandler::handleFatalError(1, 'Call to a membe...',
>> 'G:\htdocs\caked...', 178)
>> #1 [internal function]: ErrorHandler::handleError(1, 'Call to a
>> membe...', 'G:\htdocs\caked...', 178, Array)
>> #2 G:\htdocs\cakedemo\lib\Cake\Core\App.php(924):
>> call_user_func('ErrorHandler::h...', 1, 'Call to a membe...',
>> 'G:\htdocs\caked...', 178, Array)
>> #3 G:\htdocs\cakedemo\lib\Cake\Core\App.php(897): App::_checkFatalError()
>>
>> *my Controller*:
>> <?php
>> App::uses('AppController','Controller');
>> class GeneralsController extends AppController{
>> var $helpers = array('CakeGrid.Grid');
>> public function apply(){
>> $this->set('name','general.apply');
>> }
>> public function mid(){
>> $this->set('name','general.mid');
>> }
>> public function end(){
>> $this->set('name','general.end');
>> }
>> }
>>
>> *my View: (apply.ctp)*
>> <h1> <?php echo $name;
>> echo '<br>';
>> echo __('Role');
>> $this->Grid->addColumn('Order Id', '/Order/id');
>> $this->Grid->addColumn('Order Date', '/Order/created', array('type' =>
>> 'date'));
>> $this->Grid->addColumn('Order Amount', '/Order/amount', array('type' =>
>> 'money'));
>>
>> $this->Grid->addAction('Edit', array('controller' => 'orders', 'action'
>> => 'edit'), array('/Order/id'));
>> debug( $this->Grid);
>> echo $this->Grid->generate($results);
>> ?> </h1>
>>
>> *the GridHelper.php*
>> function generate($results){
>> //$View = $this->__view();
>> $View=&ClassRegistry::getObject('view');
>> $directory = $this->__settings['type'];
>> if($this->__settings['type'] == 'csv' && !empty($this->__totals)){
>> array_unshift($this->__columns, array(
>> 'title' => '',
>> 'valuePath' => '',
>> 'options' => array(
>> 'type' => 'empty'
>> )
>> ));
>> }
>> //-- Build the columns
>> $headers = $View->element($this->elemDir . DS . 'grid_headers',array(
>> *//line 178 :the error occurs*
>> 'plugin' => $this->plugin_name,
>> 'headers' => $this->__columns,
>> 'options' => $this->__settings
>> ));
>> $results = $this->results($results);
>> $generated = $View->element($this->elemDir . DS . 'grid_full', array(
>> 'plugin' => $this->plugin_name,
>> 'headers' => $headers,
>> 'results' => $results,
>> 'options' => $this->__settings
>> ));
>> return $generated;
>> }
>>
>> anyone help me,Thanks!
>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> [email protected] For more options, visit this group
>> at http://groups.google.com/group/cake-php
>>
>
>
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php