Jump to content

Adding msqli to custom PHP page


ystar

Recommended Posts

I have been creating a simple blog page for my Prestashop website. SO far I have been able to create the following files and the template is displaying correctly.

BlogController.php (located at /controllers/front directory)

    <?php
    
    class BlogControllerCore extends FrontController
     {
      public $php_self = 'blog.php';
    
      public function setMedia()
      {
              parent::setMedia();
              Tools::addCSS(_THEME_CSS_DIR_.'blog.css');
              Tools::addJS(_THEME_JS_DIR_.'blog.js');
      }
    
      public function displayContent()
      {
               parent::displayContent();
               self::$smarty->display(_PS_THEME_DIR_.'blog.tpl');
      }
    }
    ?>

blog.php (located at root directory)

    <?php
    require(dirname(__FILE__).'/config/config.inc.php');
    include(dirname(__FILE__).'/header.php');
    
    ControllerFactory::getController('BlogController')->run();
    
    include(dirname(__FILE__).'/footer.php');
    ?>

blog.tpl (located at theme directory)

    {capture name=path}{l s='Blog'}{/capture}
    
    <h1>{l s='Blog posts'}</h1>

My question is, how can I add some mysql queries (select, show) into the pages and display my blog posts (using a while loop maybe?) in the blog page?

 

I'm on Prestashop version 1.6.0.11

Edited by ystar (see edit history)
Link to comment
Share on other sites

Check documentation about DB class and working with database  

 

http://doc.prestashop.com/display/PS16/Accessing+the+database

 

also you may want to check for module

 

https://www.prestashop.com/forums/topic/317230-prestashop-blog-module/

Thanks for the reply. I looked into that documentation. I couldn't find any examples which clarifies my issue. May I ask any good source for see some examples?

 

And about the module, even if the module sounds promising, I cannot use that in my website, since it gives me a white page error without any error messages.

Link to comment
Share on other sites

First I forgot to mention that what you want needs some work.

And that is better way to do it like a module then adding global controller like that, you need a way to add post in back office

also, maybe some blog categories, some rewrite rules in Dispatcher, all similar to CMS structure. If you go to module then 

you need module controller, some classes for blog post example where you will also add functions to retrieve those post from database.

 

Well check more into documentation and also code from existing modules like

http://doc.prestashop.com/display/PS16/Best+Practices+of+the+Db+Class

http://doc.prestashop.com/display/PS16/Creating+a+PrestaShop+Module

https://github.com/PrestaShop/homeslider  or  smartblog module itself 

 

https://github.com/smartdatasoft/smartblog 

 

If you have that white page for smartblog try to enable debug mode, I remember I once had issues after installing module,

think was example blog posts, - or _ problem. Check https://www.prestashop.com/forums/topic/317230-prestashop-blog-module/ it does have 

a lot of posts but if you ask for help think smartdatasoft usually replay fast.

 

Or there is also good but paid module https://www.prestashop.com/forums/topic/305917-module-blog-for-prestashop-with-post-types/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...