cakephp-2.1

CakePHP 2.1.x - Run a query without any models in AppController

南楼画角 提交于 2019-12-03 11:08:44
问题 I am trying to run a query in AppController on a table that has no Model associated with it. I don't want to use a Model cause this query would fire on every request and I guess using a Model would make it a bit slower. I found out in one forum that this can be achieved with the following code in CakePHP 1.3 $db = ConnectionManager::getInstance(); $conn = $db->getDataSource('default'); $conn->rawQuery($some_sql); But this is not working in CakePHP 2.1.3. Any help would be appreciated. Thanks

CakePHP: How to update multiple records at the same time with the Form helper

笑着哭i 提交于 2019-12-03 08:39:42
On an edit page for the model Test I want to be able to update the "Questions.order" field on all of it's associated (by hasMany) questions from the same form. I've ready the Cake book chapter on saveMany()/saveAll() in the book, and I'm using the Model.0.field syntax but I can't figure out how to tell CakePHP which record to corresponds to which input. Should the # in Model.#.field correspond to the question's id field? Here's what I'm currently doing: echo $this->Form->create( 'Question', array('action'=>'order')); $n = 0; foreach ($questions_array as $question) : ?> <?php echo $this->Form-

CakePHP re-populate list box

江枫思渺然 提交于 2019-12-02 13:33:06
I have a question about cakePHP. I create two drop down lists in my view. When the user changes the value in one list, I want the second to change. Currently, I have this working like this: An on click event fires when the user selects from list box one. This fires a jQuery ajax function that calls a function from my controller. This is all working fine, but how do I re-render my control, asynchronously (or, view)? I i know I could just serialize the array to json and then recreate the control in javascript, but there seems like there should be a more "CakePHP" way. Isn't that what render is

Cakephp 2.1 naming convensions issue in version change

强颜欢笑 提交于 2019-12-02 13:25:22
I have just installed CakePHP 2.1. And just see that the naming convention of its is just change lot from the older version which making me crazy. Like it was app/controllers while now it is app/Controller same way app/models - app/Model app/views - app/View I know there must be some advantage on doing this. But my problem is when I use the cake bake it is creating directory in the same old fashion i.e. controllers/models/views . Which is no more accessible from the URL & obviously will throw an error. Is anyone there who has face the same issue ? Is there any solution that cake bake also use

Auth login with email or mobile Cakephp

*爱你&永不变心* 提交于 2019-12-02 12:18:57
I am working on cakephp 2.x.i have a table in my database name user and it has 4 fields id, email, password and mobileNo i have two fields in my login.ctp <?php echo $this->form->create(); echo $this->form->input('email'); echo $this->form->input('password'); echo $this->form->end('submit'); ?> what i want is i want to login the user from his mobileNo too(if he typed mobile number rather then email address) just like facebook has done ..he can either login with hi email address or mobileno .i dont want to create another input field.. i dont know how can i do this here is my code AppController

Using email instead of username in CakePHP Auth Component

风流意气都作罢 提交于 2019-12-01 18:36:56
I am working on cakephp 2.x . my problem is i dont want to use username for logging .. i am taking the email and password from the user and verify this email and password from the database i have a table in my database name user and it has 3 fields id , email and password here is my code Model <?php class User extends AppModel { public $useTable = 'user'; } ?> AppController class AppController extends Controller { public $components = array( 'Session', 'Auth'=>array( 'loginRedirect'=>array('controller'=>'users', 'action'=>'admin'), 'logoutRedirect'=>array('controller'=>'users', 'action'=>

Global variable in controller cakephp 2

泄露秘密 提交于 2019-12-01 08:10:39
What's the way to have a global variable inside a controller? I have tried to do it using beforeFilter but it is not accessible from the others functions. Can it only be done using Configure::read and Configure::write you can set variable accessible in any controller in your AppController class AppController extends Controller { public $myGlobalVar; public function beforeFilter() { //this can be anything array, object, string, etc ..... $this->myGlobalVar = "test2"; } } then in your other controller you can access variable anywhere like this class TestController extends AppController { public

CakePHP 2 separate login tables

杀马特。学长 韩版系。学妹 提交于 2019-11-30 10:17:29
I have a Cake website and it needs to have two separate logins, each one will have their own login form and see different pages, it would be nice to have two different tables because there are no similarities between the two types of people. Each login form will only be used by certain people and they will never login to the other form, and vice versa. Also, the two login tables have a relationship between them, which requires 2 tables? Is this possible? First, add a couple of empty custom authenticate objects. We'll reuse the same logic that FormAuthenticate uses (that is, uses POST data to

want to remove action name from url CakePHP

风格不统一 提交于 2019-11-29 17:33:24
i am working on a Cakephp 2.x.. i want to remove the action or controller name from url ... for example i am facing a problem is like that i have a function name index on my Messages controller in which all the mobile numbers are displaying the url is www.myweb.com/Messages now in my controller there is a second function whose name is messages in which i am getting the messages against the mobile number so now my url becomes after clicking the number is www.myweb.com/Messages/messages/823214 now i want to remove the action name messages because it looks weired... want to have a url like this

Defining global conditions in Model

别说谁变了你拦得住时间么 提交于 2019-11-29 11:15:51
Is it possible to define global conditions for Model ? I have 2 Models: User and Student . In database both of them are using table users but each student has set parent_id to its owner (which is set in the same table) while each user has parent_id set to Null . When I use for example $this->find('all'); in Student Model I want to force Cake to return only those records from database table users where parent_id != Null . So the question is - can I define somehow global conditions in the Model? Something like that: public $conditions = array('Student.parent_id !=' => Null); Use beforeFind You