I'm new to laravel .
I want to work with php artisan tinker in cygwin but I am getting some errors in making an object. I watched some videos and the guy did this:
$article = new app\articles;
but when I do this it says:
PHP Fatal error: Class 'app\articles' not found in eval()'d code on line 1
I tried this too:
$article = new c://xampp/htdocs/laravel/app/articles;
but it says this:
PHP Parse error: Syntax error, unexpected ':' on line 1
Tinker is case sensitive so if you are trying to create the object the way you are doing it it will fail so instead try placing the whole namespace in the exact way it is on your project
$article = new App\Article;
Use terminal to go to your project, and type :
php artisan tinker
Then type the following command for example to create a new Article:
$article = new Article;
After that you can manipulate the article like any Article object :
$article->title = "foo";
Maybe you should take a look at Laravel Fundamentals at laracasts.com, it's a greate serie for Laravel beginners.
Regards.
Related
I have created a console command and I need to truncate a table.
Reading the Class reference: http://www.yiiframework.com/doc-2.0/yii-db-command.html#truncateTable()-detail I am not able to understand what files I need to include in order to execute this command.
I am including:
use yii\db\Command;
use yii\db\Connection;
but not sure which one is correct.
And I have tried to execute:
$command = Yii::$app->db->truncateTable('user');
which gives me the following error:
Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: yii\db\Connection::truncateTable()'
and:
Yii::$connection->createCommand()->truncateTable('user');
which gives me the following error:
PHP Fatal Error 'yii\base\ErrorException' with message 'Access to undeclared static property: Yii::$connection'
I really don't understand what I need to do.
Yii::$app->db->createCommand()->truncateTable('user')->execute();
Using yii2 migrate that default function
yii2 migrate
Step 1. Create a migrate
yii migrate/create truncate_table_xxx
Step2. Edit file xxx_truncate_table_xxx
Some thing like that
class m150101_185401_truncate_table_xxx extends Migration
{
$this->dropTable('xxx')
}
Alternatively one may use:
User::deleteAll();
assuming User is active model class.
This command shows the number of deleted records.
Note, that unlike truncate deleting all records will NOT reset autoincrement counter to 1.
I'm following along with this set of tutorials on laravel (They're excellent), and I keep running into this error:
PHP error: Use of undefined constant Article
whenever I enter this line of code:
$article = new App/Article;
I've followed everything to the letter, and used the command:
$ php artisan make:model Article
Model created successfully.
Created Migration: 2015_04_11_152306_create_ar
What I find unusual is that in the tutorial, no migration was created when this command was called. Anyways, I'm trying to enter some data into my sqlite database through tinker, but I'm unable to create an Article object, and therefore cannot insert into the database. How would I got about either solving or bypassing this issue?
You should use backslash \:
$article = new App\Article;
I had doctrine version 2.3.2 , whose CLI tool was working perfectly. Now, just trying to update to ORM v2.4.4, which is having the following error just by running "./vendor/bin/doctrine" command:
PHP Catchable fatal error: Argument 1 passed to
Doctrine\ORM\Tools\Console\ConsoleRunner::run() must be an instance of
Symfony\Component\Console\Helper\HelperSet, integer given, called in
/vagrant/vendor/doctrine/orm/bin/doctrine.php on line 59 and defined in
/vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php on line 57
Can anybody please explain what might be wrong? Thanks.
OK, I found the solution. This requires little change in cli-config as below:
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
return $helperSet;
In previous versions, only including the cli-config.php file would be OK(it expected a variable named '$helperSet' ). But, in new version, it requires to return the variable and get it assigned to its internal variable.
When using the described in the Google Contacts API example simple.php, and the Google API PHP Client from GitHub, version 1.0.4-beta, I get the following error:
Fatal error: Call to undefined method Google_IO_Curl::authenticatedRequest()
However, when I change this line...
$val = $client_svc_contacts->getIo()->authenticatedRequest($req);
...to...
$val = $client_svc_contacts->getAuth()->authenticatedRequest($req);
...then it starts working again.
I am using version 1.0.4-beta unmodified except for the addition of the following line at the top of Client.php:
set_include_path(str_replace('/Google','',dirname(__FILE__)));
I recognize that simple.php was written for version 0.6, not v1+, but is the example just out of date compared to the version on GitHub? Or is there something wrong with my implementation?
Found a migration guide that had the answer ...
A new home for authenticatedRequest
The authenticatedRequest method has been moved from the io classes to
the auth classes.
So it appears that replacing getIo() with getAuth() was the correct course of action.
I use a foreach loop to loop through multiple seed urls. During each loop, I instantiate a crawler using PHPCrawl and the next seed url.
foreach($companyUrls as $companyId => $companyUrl) {
$crawler = new MyCrawler($companyUrl, $companyId);
$crawler->go();
}
It runs fine for the first loop, but throws the following error the second time through before any crawling has been done:
"Call to undefined method stdClass::receivePage() in
/data/utilities/PHPCrawl_070/classes/phpcrawler.class.php on line 201"
I have not modified the original PHPCrawl V0.70 classes in any way. I have only extended the PHPCrawler class and added process code to the handlePageData() function as described in the PHPCrawl documentation. If I run this without the foreach loop (instantiating a new class one at a time with new urls), the system works fine.
Please help!!
This is a known error and has been fixed in Version 0.71 (I was using version 0.70).
Thanks #prodigitalson for your comment.