Monday, October 24, 2016

Issue during deleting all cache in magento 2

Normally you delete all cache either using

php bin/magento cache:flush --all

Or,

rm -rf var/cache/* var/page_cache/* var/view_preprocessed/* var/generation/*

You may receive some errors as
Warning: ltrim() expects parameter 1 to be string, object given in D:\xampp\htdocs\m2\vendor\magento\framework\Code\Generator\EntityAbstract.php on line 152

Notice: Uninitialized string offset: 0 in D:\xampp\htdocs\m2\vendor\magento\framework\Autoload\ClassLoaderWrapper.php on line 81

Notice: Uninitialized string offset: 0 in D:\xampp\htdocs\m2\vendor\composer\ClassLoader.php on line 317

Notice: Uninitialized string offset: 0 in D:\xampp\htdocs\m2\vendor\composer\ClassLoader.php on line 349
exception 'RuntimeException' with message 'Source class "" for   "Magento\Framework\App\Response\Http\Interceptor" generation does not exist.'
in D:\xampp\htdocs\m2\vendor\magento\framework\Code\Generator.php:185 Stack trace:     #0  
D:\xampp\htdocs\m2\vendor\magento\framework\Code\Generator.php(112): Magento\Framework\Code\Generator->tryToLoadSourceClass('Magento\\Framewo...', Object(Magento\Framework\Interception\Code\Generator\Interceptor)) #1 
D:\xampp\htdocs\m2\vendor\magento\framework\Code\Generator\Autoloader.php(35): Magento\Framework\Code\Generator->generateClass('Magento\\Framewo...') #2 [internal function]: Magento\Framework\Code\Generator\Autoloader->load('Magento\\Framewo...') #3 
D:\xampp\htdocs\m2\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(93): spl_autoload_call('Magento\\Framewo...') #4 
D:\xampp\htdocs\m2\vendor\magento\framework\ObjectManager\Factory\Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Magento\\Framewo...', Array) #5 
D:\xampp\htdocs\m2\vendor\magento\framework\ObjectManager\Factory\Compiled.php(130): Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\\Framewo...') #6 
D:\xampp\htdocs\m2\vendor\magento\framework\ObjectManager\Factory\Compiled.php(67): Magento\Framework\ObjectManager\Factory\Compiled->get('Magento\\Framewo...') #7     
D:\xampp\htdocs\m2\vendor\magento\framework\ObjectManager\ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Compiled->create('Magento\\Framewo...', Array) #8 
D:\xampp\htdocs\m2\vendor\magento\framework\App\Bootstrap.php(233): Magento\Framework\ObjectManager\ObjectManager->create('Magento\\Framewo...', Array) #9
On this situation you all can do is re compile the files as
php bin/magento setup:di:compile
After all the problem is solved.

Tuesday, September 27, 2016

How to reset lost admin password in Magento 2 ?

If you forgot your admin password in magento 2 in localhost you cann't retrieve by just clicking on lost password. For that you can reset through Magento CLI, then you can easily change password of your original user.

Go inside magento directory and type:

php bin/magento admin:user:create --admin-use="admin" --admin-password="admin123" --admin-email="admin@gmail.com" --admin-firstname="Admin" --admin-lastname="Admin"



Monday, September 26, 2016

How to render static blocks in any pages in magento 2

In between Magento 1.x and 2.x, rendering the Static block is quiet different. You can call either in .phtml template, CMS page or layout file in the following way.

In phtml file:
<?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block-identifier')->toHtml();?>

In any CMS block:
{{block class="Magento\Cms\Block\Block" block_id="block-identifier"}}

In layout file:
<referenceContainer name="content">
<block class="magento\Cms\Block\Block" name="block-identifier">
<arguments>
<argument name="block_id" xsi:type="string">block-identifier</argument>
</arguments>
</block>
</referenceContainer>