Skip to content

Console : How do I use the console?

Mark Moran edited this page Dec 10, 2013 · 1 revision

The console gives you access to your Trax Environments|Environment where you can interact with the domain models. Here you’ll have all parts of the application configured, just like it is when the application is running. You can inspect domain models, change values, and save to the database. As well you can execute any valid php code and it will evaluate it. It's freakin sweet try it out! Console options

(environments are development,test,production)

./console.php [environment]

Starting the console

First you need to bring up your commandline and cd to your script folder

[root@bsd1 /home/phpontrax/dev/trax/script]# ./console.php 
Loading Trax development environment.
>> use '?' to open the inline help 
>> 

Instantiate and Find a Model

Now that your console is loaded up in the Trax development environment we can access any of any of our models. Lets find a user change his name and save to the database.

>> $u = new User
User::__set_state(array(
   'content_columns' => 
  array (
..
..
..
   'auto_timestamps' => true,
   'auto_save_habtm' => true,
   'auto_delete_habtm' => true,
))
>>

Now we have a dummy object lets find user 1

>> $u = $u->find(1)
User::__set_state(array(
   'content_columns' => 
  array (
..
..
..
   'auto_timestamps' => true,
   'auto_save_habtm' => true,
   'auto_delete_habtm' => true,
   'id' => '1',
   'name' => 'John',
))
>> 

Ok we loaded id = 1, name = 'John' successfully now lets change the name to Steve and save it.

>> $u->name ='Steve'
'Steve'
>> $u->save()
true
>> 

Cool it looks like it saved successfully! Now lets just reload the object to make sure we aren't cheating.

>> $u->reload()
true
>> $u
User::__set_state(array(
   'content_columns' => 
  array (

..
..
..
   'auto_timestamps' => true,
   'auto_save_habtm' => true,
   'auto_delete_habtm' => true,
   'id' => '1',
   'name' => 'Steve',
))
>> 

So yes the console is using the applications environment just like your web application would but from the commandline.