I need a display element depending on whether the user is registered or not - In CakePHP 2.0
This does not work
<?php if ($this->Auth->loggedIn() { echo $this->element('user'); } else { echo $this->element('guest'); } ?>
thanks
Follow the MVC pattern and put the logic in the controller.
In the controller:
$this->set( 'loggedIn', $this->Auth->loggedIn() );
In view:
if( $loggedIn ) { echo $this->element( 'user' ); } else { echo $this->element( 'guest' ); }
Use the session assistant (required for authentication, as shown in the "log tutorial"):
if ($this->Session->read('Auth.User')) { echo 'logged'; } else { echo 'guest'; }
Try the following:
$element = (AuthComponent::loggedIn()) ? 'user' : 'guest'; echo $this->element($element);
Pretty similar to what you have already tried, but then statically set the loggedIn method.
!$this->Session->check('marketplace_showlink'
if in the above code an error occurs that is encoded in appcontroller
appcontroller
as:Calling a member function of a function () for a non-object
it will be generated due to an empty session variable
Source: https://habr.com/ru/post/1397317/More articles:How to stop the exit program when clicking the red cross in the JFrame title bar - javaHow to deserialize xml for an object without locking the file? - c #How to receive notifications when iPhone enters airplane mode? - objective-cRefactoring The Dilemma: User Account Functionality in PHP - oopEasy template options for mobile website - jquery-mobileHow to create a matrix of confusion containing many judgments in R? - rHow do you limit CPU usage on Windows? (need code, not application) - windowsReading a value without using partitions - delphiPHP discovers Internet Explorer which is lower than version 10 - browserPHP get_browser: how to define ie7 compared to ie6? - internet-explorerAll Articles