execute php app/console doctrine:schema:update from controller symfony 2 - doctrine

I want to execute this command
php app/console doctrine:schema:update
from the controles without use exec php function,
Any comment will be use full to me.
Thanks!!!

If you are looking here, on the bottom there is an example of how to execute a command from within symfony code.
Please also mind the note on the end saying that it might not be a good idea to use a command within your code.
As said, the following code should be used with care. I wouldn't use it for the reasons statet in the symfony doc, but it works.
When using the following code within your controller, you are able to execute a command:
$kernel = $this->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
$options = array('command' => 'list');
$application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
If you need the output, you have to either use an existing class implementing OutputInterface or create your own depending on your needs.

Thanks to every one,
I used this code
$kernel = $this->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
//Create de Schema
$options = array('command' => 'doctrine:schema:update',"--force" => true);
$application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
//Loading Fixtures
$options = array('command' => 'doctrine:fixtures:load',"--append" => true);
$application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
and in this link, there are some information maybe will be usefull for others
Thanks!!!

Related

laravel - update the model(!) without selecting first

I have the following ResearchModel (eloquent):
$research = new ResearchModel();
$research->id = 2;
$research->name = "test";
$research->save();
I am expecting Laravel to run an update statement (because I set the id), but it runs an insert statement instead.
$research->update(); wont do anything.
I don't want to use array in this case because I need the eloquent model events to be triggered.
I also don't want to run ResearchModel::find(2); before, this will cause significant performance problems in my use-case.
Is there any way to tell Laravel to update by the id?
Thanks
If you don't want to "select" first. Then you can update directly. This will run only one query.
$research = ResearchModel::where('id',2)->update([
'name' => 'test',
]);
A dirty solution:
// Create an instance without insert to database.
$instance = new ResearchModel;
$instance->id = 2;
$instance->name = "test";
// Set the instance status directly.
$instance->exists = true;
// Update database without model.
ResearchModel::where('id', $instance->id)
->update(['name' => $instance->name]);
// Manually trigger event.
event('eloquent.updating: App\ResearchModel', $instance);
The premise of this method is that you already have the required data. If the data required for the event must be read from the DB, then this method is useless.
Find by id
$research = ResearchModel::find(2);
Then you can run update function
$research->update([ 'name' => "test"]);
and if u don't want to use
ResearchModel::find(2);
then u have to use route binding
https://laravel.com/docs/6.x/routing#implicit-binding

Codeigniter 4 Current/Active Controller

In Codeigniter 3 is possible to get current active class and method with this code:
$active_controller = $this->router->fetch_class();
$active_function = $this->router->fetch_method();
Are there such functions in Codeigniter 4?
In CodeIgniter 4
$router = service('router');
$controller = $router->controllerName();
$router = service('router');
$method = $router->methodName();
Its worth saying those classes were never officially part of CI3 (https://codeigniter.com/user_guide/installation/upgrade_300.html?highlight=fetch_class). Bearing in mind CI4 is a lot more flexible and that routes are defined more variably I would look at the routing side of things and extract it from there (https://codeigniter4.github.io/userguide/incoming/incomingrequest.html#the-request-url).
You can use PHP constant or functions that provide you the same:
Get Current Function name:
__FUNCTION__
Get Current Class name:
__CLASS__
OR
get_class()
Codeigniter 4: All the above is working well otherwise use the same code that #mathan answered:
$router = service('router');
echo $router->controllerName();

Joomla 3 - How to get value from configuration file?

I'm building a custom component and I just want to get a value from the global config in my controller. I can't find any information about how to do this.
Something like...
$config = JFactory::getConfig();
$this->_db = $config->get('db');
The documentation on how to do it is slightly outdated:
http://docs.joomla.org/JFactory/getConfig
But if you check the code they actually drop the ampersand function:
https://github.com/joomla/joomla-cms/blob/staging/components/com_users/models/registration.php
$config = JFactory::getConfig();
$fromname = $config->get('fromname');
Also if you are trying to connect to the database you really can just use the DB object from JFactory.
$db = JFactory::getDbo();
Learn more about properly connecting to the database here:
http://docs.joomla.org/Accessing_the_database_using_JDatabase
Since Joomla 3.2:
JFactory::getApplication()->get($varname, $default);
See the reference

Using X-Editable - Backend part

So I'm just trying to use xeditable (http://vitalets.github.io/x-editable/docs.html#gettingstarted) to make changes to my database via AJAX.
Since I'm new to this concept and I'm (forcefully) working with PHP for the first time, I need some help.
I setup the frontend part, and a script called (say) script.php is handling the data for me (I need to write the new value in my database).
I can't really understand what to do in the script. Can someone guide me towards it? The docs above don't really do it for me.
Looking in a project I worked on a few months back (sorry about the mysql_ stuff – not my choice!)
Something like:
<?
include your/database/connection_stuff.php;
// Can't remember if x-editable passes the table in as well or not
$table = mysql_real_escape_string($_GET['table']);
// If not,
$table = 'name_of_table';
$value = mysql_real_escape_string($_POST['value']);
$name = mysql_real_escape_string($_POST['name']);
$pk = mysql_real_escape_string($_POST['pk']);
$result = mysql_query("UPDATE `$table` SET `$name` = '$value' WHERE id = '$pk'");
?>
Will do the trick.

Magento Product Insert Function

I need to add a custom option to all products as they get saved. For that I need to find the function that inserts the products into the database, which I'm not able to find.
Please, any help would be appreciated.
thanx
$client = new SoapClient('http://www.magentolocal.it/api/?wsdl');
$session = $client->login('productloader', '1234567890');
$sku = "123456";
$attrs['name'] = "Template #1";
$attrs['description'] = "This is the first template.";
$attrs['short_description'] = "This is the short description of the template";
$attrs['websites'] = array('1');
$attrs['price'] = "11.53";
$attrs['categories'] = array('35');
$attrs['images'] = array()
$result = $client->call($session, 'catalog_product.create', array('simple', '63', $sku, $attrs));
echo $result;
$client->endSession($session);
Magento's EAV system is pretty strung out among several files, so you won't find a single function that accomplishes what you want. If you did go looking for it, and changed it, you would also be changing the same save method that mostly every other object in Magento uses, which is probably not what you want.
To do what you want, try setting up an observer/listener on the events that catalog products use when saving, namely catalog_product_save_before or catalog_product_save_after. That way, you don't have to hack the framework.
Hope that helps!
Thanks,
Joe
How about http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.create?

Resources