Skip to content

Instantly share code, notes, and snippets.

@syphoxy
Last active August 29, 2015 13:56
Show Gist options
  • Save syphoxy/ca50983aa32daaaf7e1b to your computer and use it in GitHub Desktop.
Save syphoxy/ca50983aa32daaaf7e1b to your computer and use it in GitHub Desktop.
<!-- Your mixed HTML+PHP page script (pseudo-code) -->
<?php mysql_connect(/* database details */) ?>
<?php $result = mysql_query(/* get current page from db */) ?>
<?php $page = mysql_fetch_assoc($result) ?>
<html>
<head>
<title><?php echo htmlentities($page['title']) ?></title>
</head>
<body>
<h1><?php echo htmlentities($page['title']) ?></h1>
<ul>
<?php $result = mysql_query(/* SQL Query */) ?>
<?php while($row = mysql_fetch_assoc($result)): ?>
<li><?php echo htmlentities($row['title']) ?></li>
<?php end ?>
</ul>
</body>
</html>
<?php // Your Post Model Class (pseudo-code)
class PostModel extends ModelAbstract
{
// model specific code here
}
<?php // Your Index Controller Class (pseudo-code)
class IndexController extends ControllerAbstract
{
public function showAction($request)
{
// call on Post model to get by ID
$post = new PostModel($request->id);
// expost post to view script
$this->view->post = $post;
}
}
<!-- Your controller action template (pseudo-code) -->
<html>
<head>
<title><?php echo htmlentities($this->post->title) ?></title>
</head>
<body>
<h1><?php echo htmlentities($this->post->title) ?></h1>
<p><?php echo $this->post->content ?></p>
</body>
</html>
<?xml version="1.0"?>
<config>
<modules>
<NAMESPACE_Twitter>
<active>true</active>
<codePool>local</codePool>
</NAMESPACE_Twitter>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<NAMESPACE_Twitter>
<version>0.0.1</version>
</NAMESPACE_Twitter>
</modules>
<global>
<blocks>
<twitter>
<class>NAMESPACE_Twitter_Block</class>
</twitter>
</blocks>
</global>
</config>
<?php
class NAMESPACE_Twitter_Block_Timeline extends Mage_Core_Block_Template
{
public function getTimeline($username, $limit)
{
$tweets = array();
// code to get tweets here
return $tweets;
}
}
<!-- let's add a block to our layout that defines
where to inject our twitter widget -->
<catalog_product_view>
<reference name='product.info'>
<block type='twitter/timeline' name='product.info.twitter.timeline' as='product.view.twitter.timeline' template='catalog/product/view/twitter/timeline.phtml' />
</reference>
</catalog_product_view>
<div id='twitter-timeline'>
<?php foreach ($this->getTimeline('demacmedia', 2) as $tweet): ?>
<div class='tweet'><?php echo $tweet['text'] ?></div>
<?php end ?>
</div>
<?php echo $this->getChildHtml('product.info.twitter.timeline') ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment