Cakephp How to access AppController function in ctp file? - php

I am unable to access AppController.php function in my ctp file.
Please check my code:
AppController
public function commonEmotions($text=null){
$this->loadModel("Sticker");
$this->loadModel("Smiley");
//Smiley
$getSmiley=$this->Smiley->find('all',array('fields'=>array('Smiley.image','Smiley.symbol')));
$emotions=$this->Custom->parseEmotions($text,$getSmiley);
//Sticker
$getSticker = $this->Sticker->find('all',array('fields'=>array('Sticker.uniq_id','Sticker.image')));
$message=$this->Custom->parseStickers($emotions,$getSticker);
return $message;
}
View/Messages/news_feed.ctp
echo $this->requestAction('/app/commonEmotions/'.$getNewsFeed['News_feed']['news']);
When i running my code i am getting fllowing error
Notice (8): Undefined index: News_feed [APP\View\Messages\news_feed.ctp, line 188]
Warning (2): Missing argument 1 for AppController::commonEmotions() [APP\Controller\AppController.php, line 51]

Instead of
echo $this->requestAction('/app/commonEmotions/'.$getNewsFeed['News_feed']['news']);
Do the request to any of your controllers instead of calling the app controller directly
echo $this->requestAction('/Smiley/commonEmotions/'.$getNewsFeed['News_feed']['news']);
As all your controllers inherit the method from the app controller

Related

whenever using database library,error message is displayed

whenever loading this
$this->load->library('database');
error is shown
Unable to load the requested class: database
without the above mentioned code,the following error is shown.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: LoginPage::$db
Filename: core/Model.php
Line Number: 52
Fatal error: Call to a member function select() on null in
C:\xampp\htdocs\Test_LR\application\models\Login_model.php on line 11
FIle permission From Filezilla...
Connect your FTP client to your web server. In FileZilla, right-click the "system" folder on your web server and choose File Permissions to open the file attributes. Type the correct number in the Numeric Value text field
This means CodeIgniter has a library database.
You can include libraries in two ways:
1) In application/config/autoload.php
Code:
$autoload['libraries'] = array('database'); // Include other libraries here like `session`.
2) Run time by using $this->load->library('database'); if not included with first method.
Without it, it will show fatal error.
Have you tried to use:
$this->load->database();
Instead of $this->load->library('database');
Or double check if your database file available on system
Sample example Usersmodel.php
class usersmodel extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function examplefunction()
{
}
}

Routing in CakePHP 1.3.3 has suddenly stopped working for one folder (beforeFilter issues?)

We've had an application running on CakePHP 1.3.3 for years without a single hitch, but randomly it's started saying "The requested address /task_scheduler/task_scheduler_mailouts was not found on this server." - but it's only effecting this. Everything else running on that server (including other CakePHP applications) are fine.
When I enable debug in core.php, I get the following error messages:
Notice (8): Undefined variable: currentUser [APP\views\themed\default\layouts\default.ctp, line 50]
Error: The Behavior file app\models\behaviors\null.php can not be found or does not exist.
Error: Create the class below in file: app\models\behaviors\null.php
<?php
class NullBehavior extends ModelBehavior {
}
?>
All of the files are present in /task_scheduler/task_scheduler_mailouts and the currentUser variable is working without any problems on the other pages. currentUser is set in the beforeFilter() function in app_controller.php which as far as I know is used for every single page.
function beforeFilter() {
...
$currentUser = ClassRegistry::init('WfEmployee')->getNetworkUser();
...
}
(update) if I hardcode the $currentUser variable I still get the not set notice. I don't think the beforeFilter() function is even running.
Any ideas as to what could have suddenly caused this error please? Thank you.
function beforeFilter() {
parent::beforeFilter();
$currentUser = ClassRegistry::init('WfEmployee')->getNetworkUser();
...
}

An internal error occured in cakephp

I have a controller name ReminderController from which I wanna call admin_index.ctp.
class ReminderController extends AppController {
public function admin_index(){
$this->paginate=array('limit' =>'10');
$this->set('news', $this->paginate('Reminder'));
}
When I call view name admin_index from a controller I found an internal error has been occurred... please help me out from this problem.........
I'm not familiar with cakephp, but according to me error is in below 2 lines:
$this->paginate=array('limit' =>'10');
$this->set('news', $this->paginate('Reminder'));
Because, in the first line you are assigning an array to $this->paginate. But in the second line you are calling it as a function.

How to load two models in the same controller with CodeIgniter?

I've been searching on Internet and on stackoverflow, but i didn't find a solution, or it wasn't the same problem.
I need to load two models in the same controller, and in the same function. One is "model_membre" and the other "model_annonce". It's the name of the class, the file, and the object.
Individually, they work very good, i can access to properties and methods, but when I'm loading the two models, I can't access to the second, regardless of how I load it (autoload, $this->load->model('model_name'), $this->load->model('model_name', 'object_name')).
I simplified to a "test" controller, to see if it was not another part of my code that made the problem :
public function index()
{
$this->load->model('model_membre', 'membre');
$this->load->model('model_annonce', 'annonce');
$liste = $this->annonce->listerEspeces();
$membre = $this->membre->obtenirMembre(1);
}
I tried to changer the order, and the 2nd loaded never works. I get this message :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Test::$annonce
Filename: controllers/test.php
Line Number: 15
Fatal error: Call to a member function listerEspeces() on a non-object in /homez.604/animalix/beta/application/controllers/test.php on line 15
Please try the following way...
public function index()
{
$this->load->model(array('membre','annonce'));
$liste = $this->annonce->listerEspeces();
$membre = $this->membre->obtenirMembre(1);
}
The models should extend CI_Model and not CI_Controller! This was the source of the problem.

CakePHP Acl problems

I have a simple authentication system in place on my Cake website and only allow a user to access the index and view of my posts_controller but they cannot add or edit them. I do this with the following code:
function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allow(array('index','view'));
}
Now this works fine as they are just redirected to the login page where they can login to access the page but instead of gaining access the get the following error:
Warning (512): Could not find AclComponent. Please include Acl in Controller::$components. [CORE/cake/libs/controller/components/auth.php, line 421]
Notice (8): Undefined property: AuthComponent::$Acl [CORE/cake/libs/controller/components/auth.php, line 527]
Fatal error: Call to a member function check() on a non-object in /Users/cameron/Sites/cake-1.3.8/cake/libs/controller/components/auth.php on line 527
I'm not sure why I'm getting errors about ACL as I'm not using ACL anywhere within my app, all I'm doing is simply saying a user must be logged in to access those OTHER actions.
Any ideas what the problem is and how to fix it?
As you fall on line 527 of the AuthComponent, does it mean that somewhere you configured the AuthComponent with something like this:
$this->Auth->authorize = 'actions';
If this is the case, it has the effect to make the AuthComponent use the AclComponent to check if a user is allowed to perform an action.
See http://book.cakephp.org/view/1250/Authentication#!/view/1275/authorize

Categories