Re: Create database table using controller.
yes, deleting/refreshing/updating the listsources should solve the problem but I haven't managed to do that. I tried doing something like this: $dataSource = $this->MyModel->getDataSource(); $dataSource->listSources($updatedSourceList); It doesn't cause ant error but listSources does not get updated. My code is in a shell class so redirecting isn't really a good option for me. On Wednesday, September 5, 2012 8:05:11 AM UTC+2, Dr. Tarique Sani wrote: > > On Sun, Feb 28, 2010 at 3:04 PM, veepee > > wrote: > > I've found the problem. > > It is caused by the listsources() method in cakephp has cached the > > Right! and listsources() reads the list from a cache file similar to > myapp_cake_model_default_pathname_list > > This cache file is updated/created when a page reloads by a call to > listsources() > > > sources array which holds the array of tables available in database. > > My question now is, is it possible to reset the sources to null in my > > controller? > > You have 2 options > - figure out how to delete the cache file and call listsources() again > - *redirect* to a new action after creating the table and use the new > model there > > HTH > Tarique > > > -- > = > PHP for E-Biz: http://sanisoft.com > = > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Create database table using controller.
On Sun, Feb 28, 2010 at 3:04 PM, veepee wrote: > I've found the problem. > It is caused by the listsources() method in cakephp has cached the Right! and listsources() reads the list from a cache file similar to myapp_cake_model_default_pathname_list This cache file is updated/created when a page reloads by a call to listsources() > sources array which holds the array of tables available in database. > My question now is, is it possible to reset the sources to null in my > controller? You have 2 options - figure out how to delete the cache file and call listsources() again - *redirect* to a new action after creating the table and use the new model there HTH Tarique -- = PHP for E-Biz: http://sanisoft.com = -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Create database table using controller.
I am using cakephp vesion 2.1.0 I hope this may help you, App::import('Model', 'ConnectionManager'); $con = new ConnectionManager; $cn = $con->getDataSource('default'); $cn->query("CREATE TABLE customer (First_Name char(50), Last_Name char(50), Address char(50) default 'Unknown', City char(50) default 'Mumbai', Country char(25), Birth_Date date)" ); On Tue, Sep 4, 2012 at 8:04 PM, Julien Duhain wrote: > Hi veepee, > I am having the exact same problem. have you ever found a solution? > > On Saturday, February 27, 2010 4:46:12 PM UTC+2, veepee wrote: >> >> Hi All, >> >> I am new to cakePHP and I've tried googling for this topic but to no >> avail. I need to create a database table from controller. May i know >> is it possible to insert into the newly created table, i.e. in this >> example, the customer table using model? >> >> $this->Q->query("CREATE TABLE customer >> (First_Name char(50), >> Last_Name char(50), >> Address char(50) default 'Unknown', >> City char(50) default 'Mumbai', >> Country char(25), >> Birth_Date date)"); >> } >> $this->loadModel('Customer'); >> $this->Customers->saveAll(**data); >> >> I've tried it but this does not work. May I know if there are any >> alternatives besides creating another insert statement using >> >> $this->Q->query("INSERT INTO customer..."); >> >> -- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com. > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com. > Visit this group at http://groups.google.com/group/cake-php?hl=en-US. > > > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Create database table using controller.
Hi veepee, I am having the exact same problem. have you ever found a solution? On Saturday, February 27, 2010 4:46:12 PM UTC+2, veepee wrote: > > Hi All, > > I am new to cakePHP and I've tried googling for this topic but to no > avail. I need to create a database table from controller. May i know > is it possible to insert into the newly created table, i.e. in this > example, the customer table using model? > > $this->Q->query("CREATE TABLE customer > (First_Name char(50), > Last_Name char(50), > Address char(50) default 'Unknown', > City char(50) default 'Mumbai', > Country char(25), > Birth_Date date)"); > } > $this->loadModel('Customer'); > $this->Customers->saveAll(data); > > I've tried it but this does not work. May I know if there are any > alternatives besides creating another insert statement using > > $this->Q->query("INSERT INTO customer..."); > > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
Re: Create database table using controller.
Ok, then in your example with the customers table - have you done everything that I told you was an issue? - the tablename has to be "customers", not "customer"! - the table must have a primary key named "id"! After doing these changes, try again, then tell us the result! Enjoy, John On Feb 28, 5:10 pm, veepee wrote: > I need to create a dynamic table. The customer table is just an > example. > Something from this link could help.https://trac.cakephp.org/ticket/2366 > > Thanks, John. > > Cheers. > [snip] Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Create database table using controller.
I need to create a dynamic table. The customer table is just an example. Something from this link could help. https://trac.cakephp.org/ticket/2366 Thanks, John. Cheers. On Feb 28, 5:40 pm, John Andersen wrote: > I have no idea :) Hopefully someone else may know! > > I just wonder, why do you want to create the table only when a > customer record is to be saved! > To me that sounds like you haven't designed your database at all - or > maybe you have, but you don't see a need to create the tables until > data is needed. I am guessing here :) > > By designing you database first, you will have taken into account any > relationships between tables, and you will let the database engine > handle the constraints between tables, as well as ensuring unique keys > and so forth! > > Anyway, I hope you find a solid solution to whatever you want to > make :) > Enjoy, > John > > On Feb 28, 11:34 am, veepee wrote: > > > I've found the problem. > > It is caused by the listsources() method in cakephp has cached the > > sources array which holds the array of tables available in database. > > My question now is, is it possible to reset the sources to null in my > > controller? > > > class DataSource extends Object { > > function sources($reset = false) { > > if ($reset === true) { > > $this->_sources = null; > > } > > return array_map('strtolower', $this->listSources()); > > } > > > } > > > On Feb 28, 4:17 pm, John Andersen wrote: > > > > Yes, CakePHP will not find your table, because your table is not named > > > in plural - customers - which is why I wrote that you should conform > > > to CakePHP conventions. > > > > And do add a primary key to your customers table definition - CakePHP > > > expects there to be the ID primary key column in the table. > > > Enjoy, > > > John > > > > On Feb 28, 6:38 am, veepee wrote: > > > > > Hi John, > > > > > Thanks for your prompt reply. > > > > I have read the CakePHP book but i couldn't find a solution. > > > > I get this error, "Database table customers is not found" for the > > > > first time I run the script. > > > > However, when i refresh the page, the data will be able to save > > > > accordingly. > > > > > The scenario is as below: > > > > 1. In my database, there are no Customer table. > > > > 2. So, I use a dummy table to create the customer table. > > > > $this->Q->query("CREATE TABLE customer > > > > (First_Name char(50), > > > > Last_Name char(50), > > > > Address char(50) default 'Unknown', > > > > City char(50) default 'Mumbai', > > > > Country char(25), > > > > Birth_Date date)"); > > > > } > > > > 3. The snippet above will create the Customer table. > > > > 4. However, when I load the model for Customer, > > > > $this->loadModel('Customer'); > > > > it returns me the error "Database table customers is not found". > > > > 5. When I refresh the page, there is no error and everything works > > > > fine because the customer table has been created. > > > > > Regards, > > > > Veepee > > > > > On Feb 28, 12:58 am, John Andersen wrote: > > > > > > What is your issue here? Was the table not created, was the model not > > > > > loaded, was the data not saved? > > > > > > Also do look into the CakePHP naming conventions for tables, models > > > > > and controllers. Following those will make your life a lot > > > > > easier.http://book.cakephp.org/view/22/CakePHP-Conventions > > > > > > Another thing is that your customer table has not primary key! > > > > > > So I sincerly recomend you to read the CakePHP book first! > > > > > Enjoy, > > > > > John > > > > > > On Feb 27, 4:46 pm, veepee wrote: > > > > > > > Hi All, > > > > > > > I am new to cakePHP and I've tried googling for this topic but to no > > > > > > avail. I need to create a database table from controller. May i know > > > > > > is it possible to insert into the newly created table, i.e. in this > > > > > > example, the customer table using model? > > > > > > > $this->Q->query("CREATE TABLE customer > > > > > > (First_Name char(50), > > > > > > Last_Name char(50), > > > > > > Address char(50) default 'Unknown', > > > > > > City char(50) default 'Mumbai', > > > > > > Country char(25), > > > > > > Birth_Date date)"); > > > > > > } > > > > > > $this->loadModel('Customer'); > > > > > > $this->Customers->saveAll(data); > > > > > > > I've tried it but this does not work. May I know if there are any > > > > > > alternatives besides creating another insert statement using > > > > > > > $this->Q->query("INSERT INTO customer..."); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received
Re: Create database table using controller.
I have no idea :) Hopefully someone else may know! I just wonder, why do you want to create the table only when a customer record is to be saved! To me that sounds like you haven't designed your database at all - or maybe you have, but you don't see a need to create the tables until data is needed. I am guessing here :) By designing you database first, you will have taken into account any relationships between tables, and you will let the database engine handle the constraints between tables, as well as ensuring unique keys and so forth! Anyway, I hope you find a solid solution to whatever you want to make :) Enjoy, John On Feb 28, 11:34 am, veepee wrote: > I've found the problem. > It is caused by the listsources() method in cakephp has cached the > sources array which holds the array of tables available in database. > My question now is, is it possible to reset the sources to null in my > controller? > > class DataSource extends Object { > function sources($reset = false) { > if ($reset === true) { > $this->_sources = null; > } > return array_map('strtolower', $this->listSources()); > } > > } > > On Feb 28, 4:17 pm, John Andersen wrote: > > > Yes, CakePHP will not find your table, because your table is not named > > in plural - customers - which is why I wrote that you should conform > > to CakePHP conventions. > > > And do add a primary key to your customers table definition - CakePHP > > expects there to be the ID primary key column in the table. > > Enjoy, > > John > > > On Feb 28, 6:38 am, veepee wrote: > > > > Hi John, > > > > Thanks for your prompt reply. > > > I have read the CakePHP book but i couldn't find a solution. > > > I get this error, "Database table customers is not found" for the > > > first time I run the script. > > > However, when i refresh the page, the data will be able to save > > > accordingly. > > > > The scenario is as below: > > > 1. In my database, there are no Customer table. > > > 2. So, I use a dummy table to create the customer table. > > > $this->Q->query("CREATE TABLE customer > > > (First_Name char(50), > > > Last_Name char(50), > > > Address char(50) default 'Unknown', > > > City char(50) default 'Mumbai', > > > Country char(25), > > > Birth_Date date)"); > > > } > > > 3. The snippet above will create the Customer table. > > > 4. However, when I load the model for Customer, > > > $this->loadModel('Customer'); > > > it returns me the error "Database table customers is not found". > > > 5. When I refresh the page, there is no error and everything works > > > fine because the customer table has been created. > > > > Regards, > > > Veepee > > > > On Feb 28, 12:58 am, John Andersen wrote: > > > > > What is your issue here? Was the table not created, was the model not > > > > loaded, was the data not saved? > > > > > Also do look into the CakePHP naming conventions for tables, models > > > > and controllers. Following those will make your life a lot > > > > easier.http://book.cakephp.org/view/22/CakePHP-Conventions > > > > > Another thing is that your customer table has not primary key! > > > > > So I sincerly recomend you to read the CakePHP book first! > > > > Enjoy, > > > > John > > > > > On Feb 27, 4:46 pm, veepee wrote: > > > > > > Hi All, > > > > > > I am new to cakePHP and I've tried googling for this topic but to no > > > > > avail. I need to create a database table from controller. May i know > > > > > is it possible to insert into the newly created table, i.e. in this > > > > > example, the customer table using model? > > > > > > $this->Q->query("CREATE TABLE customer > > > > > (First_Name char(50), > > > > > Last_Name char(50), > > > > > Address char(50) default 'Unknown', > > > > > City char(50) default 'Mumbai', > > > > > Country char(25), > > > > > Birth_Date date)"); > > > > > } > > > > > $this->loadModel('Customer'); > > > > > $this->Customers->saveAll(data); > > > > > > I've tried it but this does not work. May I know if there are any > > > > > alternatives besides creating another insert statement using > > > > > > $this->Q->query("INSERT INTO customer..."); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Create database table using controller.
I've found the problem. It is caused by the listsources() method in cakephp has cached the sources array which holds the array of tables available in database. My question now is, is it possible to reset the sources to null in my controller? class DataSource extends Object { function sources($reset = false) { if ($reset === true) { $this->_sources = null; } return array_map('strtolower', $this->listSources()); } } On Feb 28, 4:17 pm, John Andersen wrote: > Yes, CakePHP will not find your table, because your table is not named > in plural - customers - which is why I wrote that you should conform > to CakePHP conventions. > > And do add a primary key to your customers table definition - CakePHP > expects there to be the ID primary key column in the table. > Enjoy, > John > > On Feb 28, 6:38 am, veepee wrote: > > > Hi John, > > > Thanks for your prompt reply. > > I have read the CakePHP book but i couldn't find a solution. > > I get this error, "Database table customers is not found" for the > > first time I run the script. > > However, when i refresh the page, the data will be able to save > > accordingly. > > > The scenario is as below: > > 1. In my database, there are no Customer table. > > 2. So, I use a dummy table to create the customer table. > > $this->Q->query("CREATE TABLE customer > > (First_Name char(50), > > Last_Name char(50), > > Address char(50) default 'Unknown', > > City char(50) default 'Mumbai', > > Country char(25), > > Birth_Date date)"); > > } > > 3. The snippet above will create the Customer table. > > 4. However, when I load the model for Customer, > > $this->loadModel('Customer'); > > it returns me the error "Database table customers is not found". > > 5. When I refresh the page, there is no error and everything works > > fine because the customer table has been created. > > > Regards, > > Veepee > > > On Feb 28, 12:58 am, John Andersen wrote: > > > > What is your issue here? Was the table not created, was the model not > > > loaded, was the data not saved? > > > > Also do look into the CakePHP naming conventions for tables, models > > > and controllers. Following those will make your life a lot > > > easier.http://book.cakephp.org/view/22/CakePHP-Conventions > > > > Another thing is that your customer table has not primary key! > > > > So I sincerly recomend you to read the CakePHP book first! > > > Enjoy, > > > John > > > > On Feb 27, 4:46 pm, veepee wrote: > > > > > Hi All, > > > > > I am new to cakePHP and I've tried googling for this topic but to no > > > > avail. I need to create a database table from controller. May i know > > > > is it possible to insert into the newly created table, i.e. in this > > > > example, the customer table using model? > > > > > $this->Q->query("CREATE TABLE customer > > > > (First_Name char(50), > > > > Last_Name char(50), > > > > Address char(50) default 'Unknown', > > > > City char(50) default 'Mumbai', > > > > Country char(25), > > > > Birth_Date date)"); > > > > } > > > > $this->loadModel('Customer'); > > > > $this->Customers->saveAll(data); > > > > > I've tried it but this does not work. May I know if there are any > > > > alternatives besides creating another insert statement using > > > > > $this->Q->query("INSERT INTO customer..."); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Create database table using controller.
Yes, CakePHP will not find your table, because your table is not named in plural - customers - which is why I wrote that you should conform to CakePHP conventions. And do add a primary key to your customers table definition - CakePHP expects there to be the ID primary key column in the table. Enjoy, John On Feb 28, 6:38 am, veepee wrote: > Hi John, > > Thanks for your prompt reply. > I have read the CakePHP book but i couldn't find a solution. > I get this error, "Database table customers is not found" for the > first time I run the script. > However, when i refresh the page, the data will be able to save > accordingly. > > The scenario is as below: > 1. In my database, there are no Customer table. > 2. So, I use a dummy table to create the customer table. > $this->Q->query("CREATE TABLE customer > (First_Name char(50), > Last_Name char(50), > Address char(50) default 'Unknown', > City char(50) default 'Mumbai', > Country char(25), > Birth_Date date)"); > } > 3. The snippet above will create the Customer table. > 4. However, when I load the model for Customer, > $this->loadModel('Customer'); > it returns me the error "Database table customers is not found". > 5. When I refresh the page, there is no error and everything works > fine because the customer table has been created. > > Regards, > Veepee > > On Feb 28, 12:58 am, John Andersen wrote: > > > What is your issue here? Was the table not created, was the model not > > loaded, was the data not saved? > > > Also do look into the CakePHP naming conventions for tables, models > > and controllers. Following those will make your life a lot > > easier.http://book.cakephp.org/view/22/CakePHP-Conventions > > > Another thing is that your customer table has not primary key! > > > So I sincerly recomend you to read the CakePHP book first! > > Enjoy, > > John > > > On Feb 27, 4:46 pm, veepee wrote: > > > > Hi All, > > > > I am new to cakePHP and I've tried googling for this topic but to no > > > avail. I need to create a database table from controller. May i know > > > is it possible to insert into the newly created table, i.e. in this > > > example, the customer table using model? > > > > $this->Q->query("CREATE TABLE customer > > > (First_Name char(50), > > > Last_Name char(50), > > > Address char(50) default 'Unknown', > > > City char(50) default 'Mumbai', > > > Country char(25), > > > Birth_Date date)"); > > > } > > > $this->loadModel('Customer'); > > > $this->Customers->saveAll(data); > > > > I've tried it but this does not work. May I know if there are any > > > alternatives besides creating another insert statement using > > > > $this->Q->query("INSERT INTO customer..."); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Create database table using controller.
Hi John, Thanks for your prompt reply. I have read the CakePHP book but i couldn't find a solution. I get this error, "Database table customers is not found" for the first time I run the script. However, when i refresh the page, the data will be able to save accordingly. The scenario is as below: 1. In my database, there are no Customer table. 2. So, I use a dummy table to create the customer table. $this->Q->query("CREATE TABLE customer (First_Name char(50), Last_Name char(50), Address char(50) default 'Unknown', City char(50) default 'Mumbai', Country char(25), Birth_Date date)"); } 3. The snippet above will create the Customer table. 4. However, when I load the model for Customer, $this->loadModel('Customer'); it returns me the error "Database table customers is not found". 5. When I refresh the page, there is no error and everything works fine because the customer table has been created. Regards, Veepee On Feb 28, 12:58 am, John Andersen wrote: > What is your issue here? Was the table not created, was the model not > loaded, was the data not saved? > > Also do look into the CakePHP naming conventions for tables, models > and controllers. Following those will make your life a lot > easier.http://book.cakephp.org/view/22/CakePHP-Conventions > > Another thing is that your customer table has not primary key! > > So I sincerly recomend you to read the CakePHP book first! > Enjoy, > John > > On Feb 27, 4:46 pm, veepee wrote: > > > Hi All, > > > I am new to cakePHP and I've tried googling for this topic but to no > > avail. I need to create a database table from controller. May i know > > is it possible to insert into the newly created table, i.e. in this > > example, the customer table using model? > > > $this->Q->query("CREATE TABLE customer > > (First_Name char(50), > > Last_Name char(50), > > Address char(50) default 'Unknown', > > City char(50) default 'Mumbai', > > Country char(25), > > Birth_Date date)"); > > } > > $this->loadModel('Customer'); > > $this->Customers->saveAll(data); > > > I've tried it but this does not work. May I know if there are any > > alternatives besides creating another insert statement using > > > $this->Q->query("INSERT INTO customer..."); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Create database table using controller.
What is your issue here? Was the table not created, was the model not loaded, was the data not saved? Also do look into the CakePHP naming conventions for tables, models and controllers. Following those will make your life a lot easier. http://book.cakephp.org/view/22/CakePHP-Conventions Another thing is that your customer table has not primary key! So I sincerly recomend you to read the CakePHP book first! Enjoy, John On Feb 27, 4:46 pm, veepee wrote: > Hi All, > > I am new to cakePHP and I've tried googling for this topic but to no > avail. I need to create a database table from controller. May i know > is it possible to insert into the newly created table, i.e. in this > example, the customer table using model? > > $this->Q->query("CREATE TABLE customer > (First_Name char(50), > Last_Name char(50), > Address char(50) default 'Unknown', > City char(50) default 'Mumbai', > Country char(25), > Birth_Date date)"); > } > $this->loadModel('Customer'); > $this->Customers->saveAll(data); > > I've tried it but this does not work. May I know if there are any > alternatives besides creating another insert statement using > > $this->Q->query("INSERT INTO customer..."); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Create database table using controller.
Hi All, I am new to cakePHP and I've tried googling for this topic but to no avail. I need to create a database table from controller. May i know is it possible to insert into the newly created table, i.e. in this example, the customer table using model? $this->Q->query("CREATE TABLE customer (First_Name char(50), Last_Name char(50), Address char(50) default 'Unknown', City char(50) default 'Mumbai', Country char(25), Birth_Date date)"); } $this->loadModel('Customer'); $this->Customers->saveAll(data); I've tried it but this does not work. May I know if there are any alternatives besides creating another insert statement using $this->Q->query("INSERT INTO customer..."); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en