how to access static variable in cakephp 2 - cakephp-2.0

I am using the following code to check the logged in user's group (cakephp 1.3)
Session->read('Auth.User.user_group_id') != User::USERLEVEL_USER) :?>
(this is in .ctp file)
and now am migrating to cakephp 2. and this code is not working.
cant find any results when I googled .
Could anyone shed some light on this

in cakephp 2.x you're sending variables to view, so you don't have access to User class. you should get instance of this class in controller and send it as a variable to view.
please use this plugin to improve your debugging skills:
https://github.com/cakephp/debug_kit

Related

Loopback : How to get one model data from other mode service method?

I'm using loopback angular sdk I'm having two models Tags and Project. I want to get Tags related to that project. I'm having lb-services. I don't know what method to call and how to call it from services. please help. I've tried this code to get tags which is related to project who's id is 1.
Project.Tag.find(
{ id: 1 }
);
Here's an example from a live app ... For a relationship described like so:
https://github.com/ShoppinPal/warehouse/blob/490cbaccfb60922645173a34d53327629b989028/common/models/user-model.json#L28
I can pull the related models on the angular side like so:
https://github.com/ShoppinPal/warehouse/blob/dbf8d1e25592ec9e76d9f6a5f2af6ba6ca74fd9c/client/app/scripts/controllers/login.js#L57
If your problem is purely syntactical then please paste code from model.json file as well so the community can help detect & fix it.

load model from another module

I'm new in CakePHP. Currently I got a problem in my task.
I had assigned to create a Plugin name UserManagement and Login in app/Plugin/
The Plugin UserManagement already has completed. But now I having a problem in Plugin Login. Actually I need to use User Model from Plugin UserManagement in Plugin Login. However, I don't know how to write a scripts and what steps first I should taken?
I try before, create LoginsController in Controller. But It display an error mentioned that I need to create Model first. Infact that, I actually plan to use Model from UserManagement.
Please assists. Thank you.
Sorry..my English is bad. TT_TT
You have to add
$this->loadModel(PluginName.ModelName);
in our controller and then
$data = $this->ModelName->find('WhatEver');
Hope this will give you some help.

Existing view template not found

CakePHP is giving me a mysterious error when trying to create a new view via $view = new View($this, false) on my server. The script runs perfectly on my local machine. On the server it says the view, that i want to render via this method wasn't found.
I have already tried chown/chmod. The file rights of all View files are all the same.
The URL to the guide which explains the concept is the following:
http://wp.headynation.com/cakephp-get-htmloutput-of-view-without-view-displaying-or-outputting-using-render/
Thank you
I found the solution: I have to use $view->render('/Exports/_users.ctp'); instead of $view->render('_users');

CakePHP - BlogTutorial -

I was following pdf blog tutorial, and in the PostsController where $this->Post should be available another method postConditions() is the only choice. According to the PDF Post is accessible due to the naming conventions. But it is not in my case.
I have created:
model Post.php - according to the pdf
Controller PostsController - according to the pdf
I use PhpStorm IDE to help me out with the stuff....
What did i do wrong? Could someone help me out?
I am using Cake 2.3.0 Stable on localhost XAMP
Thanks
I'm assuming you mean autocomplete in your editor is not working?
CakePHP dynamically loads classes as and when they are references, your editor does not, so it is unaware of what Post is as it doesn't know anything about it.
I don't use PhpStorm, but here's someone who's says they've got it working: http://blog.hwarf.com/2011/08/configure-phpstorm-to-auto-complete.html

Cakephp twitter autopost

I need to post a product details in twitter whenever it is added in my website.I am using Cakephp, and i use twitter datasource available in book.cakephp.org . It returns a 'Basic authentication is not supported ' message
when i searched it, i get that twitter is now using OAuth, how can i impliment this in my data source?. i did it referring the below url
http://book.cakephp.org/view/1077/An-Example
Anybody please help.
The Cake Book link seems to be out of date and relevant to the time before Twitter implemented OAuth.
I have accomplished what you're trying to do using http://code.42dh.com/oauth/ but this is basically a controller and a component, not a datasource as you asked.
There's a CakePHP OAuth Datasource for CakePHP which might work (I haven't tried it) but you'll need to add the PHP Oauth library too. If you choose to do this, let me know if it works as interacting with Twitter as a datasource makes a lot more sense, especially as Cake are depreciating components.
I have created this - it isnt a datasource but it provides a model you can use to accomplish what you need to do:
https://github.com/voycey/CakePHP-Twitter-API-v1.1-Full
You can either use a Shell to have it post automatically or you can just call it in your controller when you add your entity.

Resources