Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Posts posted by The Little Guy

  1. Am I missing something? Whenever I try to append data to the end of a string from an array, it doesn't get put there.

     

    Class Template{
    public static $items = array();
    static public function append($key, $data){
    	if(!isset(self::$items[$key])){
    		self::$items[$key] = "";
    	}
    	self::$items[$key] .= $data;
    }
    }

     

    Example:

     

    class ClassA{
    public function __construct(){
    	Template::append("CONTENT", "This is ClassA");
    }
    }
    class ClassB{
    public function __construct(){
    	Template::append("CONTENT", "This is ClassB");
    }
    }
    
    $classA = new ClassA();
    $classB = new ClassB();
    print_r(Template::$items);
    

     

    When I do a print_r, the only thing in $items is This is ClassA What isn't This is ClassB in there?

  2. that can be edited/updated in a form

    Why would it be? It's something you want people to configure using an easy UI tool? Not a one-time thing?

     

    Yes, it is a UI tool for my CMS, in case someone changes the name of the db, username, password, host, etc. and they don't know php they can easily do it via this instead of finding the file and trying to figure it out.

  3. I am trying to think of the best way to store database login information (user, pass, host, database) that can be edited/updated in a form, and still not be view able in a browser without the use of htaccess, and still resided in a sub directory of the root.

     

    I was thinking of just writing the php code to a file whenever the form is submitted, but that doesn't seem logical.

     

    Any suggestions?

  4. Okay I am starting to feel really stupid, but I feel like I am doing exactly that, and yet I am still having the same problem.

     

    Here are my EXACT files (except for the template one that is too long too post).

     

    /includes/setup.php

    <?php
    require_once __DIR__."/settings.php";
    function __autoload($class){
    if(is_file(__DIR__."/../classes/$class.php")){
    	require_once __DIR__."/../classes/$class.php";
    }
    }
    use Cleep\Classes\Cleep,
        Cleep\Classes\Template,
        Cleep\Classes\Hook;
    $cleep       = new Cleep();
    $library     = $cleep->activeTemplate();
    $plugins     = $cleep->getActivePlugins();
    $template    = new Template($library);
    $hook        = new Hook();

     

    /index.php

    <?php
    /**
    * @var $temp Template
    * @var $plugins ArrayObject
    */
    require_once "includes/setup.php";
    $template->metaTags(array(
    "description" => "This is a test",
    "keywords" => "one,two,three"
    ));
    
    $hook->triggerHook("index.content");
    
    $template->display("index.tpl");

     

    /classes/Cleep.php

    <?php
    namespace Cleep\Classes;
    use Cleep\Classes\Template;
    class Cleep extends Template{
    public function __construct(){
    	parent::__construct();
    }
    public function activeTemplate(){
    	return $this->db->getOne("select directory from templates where is_active = 1");
    }
    public function getActivePlugins(){
    	$plugins = array();
    	$this->db->query("select * from plugins where is_active = 1");
    	while($row = $this->db->row()){
    		$plugins[] = $row;
    	}
    	return $plugins;
    }
    }

     

    /classes/Template.php

    <?php
    namespace Cleep\Classes;
    use Cleep\Classes\Base;
    class Template extends Base{
    //The rest of the file...

  5. Okay, so I removed the class name from the calls, so it now looks like this:

     

    namespace Cleep\Classes;
    use Cleep\Classes;
    class Cleep extends Template{
    
    // And:
    
    namespace Cleep\Classes;
    use Cleep\Classes;
    class Template extends Base{

     

    And I am still getting the same error.

  6. Am I doing this correctly? I am just learning on how to use namespaces in php, as I have never used them before.

     

    Cleep.php

    <?php
    namespace Cleep\Classes\Cleep;
    use Cleep\Classes\Template;
    class Cleep extends Template{

     

    Template.php

    <?php
    namespace Cleep\Classes\Template;
    use Cleep\Classes\Base;
    class Template extends Base{

     

    When I run it, I get the following error:

     

    Fatal error: Class 'Cleep\Classes\Template' not found in /home/ryannaddy/cms.cleep.us/classes/Cleep.php on line 4

     

     

     

    I have a setup.php file which has __autoload() in it, and index.php includes it. Once I put the namesame and the use in, I got the above error.

  7. So I kinda changed it up, taking some of your guy ideas (Thanks for the thoughts/help).

     

    What do you think of me taking this approach.

     

    <?php
    /**
    * @var $hook Hook
    * @var $template Template
    */
    
    $blog = new stdClass();
    $blog->hi = function($name) use ($template){
    $template->assign("CONTENT", "Hi $name, I am a blog!");
    };
    
    
    $hook->register("blog", $blog); // Registers the blog class using the name blog

     

    <?php
    /**
    * @var $hook Hook 
    */
    $hook->trigger("blog.hi", "Ryan");

  8. actually "add" should be "assign", it is from my template class, and I can not have a second template instance so, my: Hook extends Cleep extends Template extends Base.

     

    I don't really understand your example, there isn't enough information.

  9. I am kinda stumped or maybe even confused....

     

    But with what you guys are saying, I have the following:

     

    /classes/Hook.php

    <?php
    class Hook extends Cleep{
    public $listeners = array();
    public function __construct(){
    	parent::__construct();
    }
    public function register($name, $callback){
    	$this->listeners[$name] = $callback;
    }
    public function trigger(){
    	$args = func_get_args();
    	$argNum = count($args);
    	if($argNum < 1)
    		trigger_error("Insufficient arguments", E_USER_ERROR);
    	$hook_name = array_shift($args);
    	return call_user_func($this->listeners[$hook_name], $args);
    }
    }

     

     

    /includes/setup.php

    $hook = new Hook();
    foreach($plugins as $plugin){
    $plugin = $plugin["directory"];
    $file = __DIR__."/register_plugins/$plugin.php";
    if(is_file($file)){
    	require_once $file;
    }
    }

     

    /includes/register_plugins/$plugin.php

    $hook->register("hi", function(){
    $this->add("CONTENT", "Hello! I Am A Blog");
    });

     

    The part I am stumped on, is how can I use $this->add("CONTENT", "Hello! I Am A Blog"); because I am getting this:

    Fatal error: Using $this when not in object context in /includes/register_plugins/blog.php on line 4

     

    Am I doing something wrong or missing something?

  10. here is what I did:

    foreach($plugins as $plugin){
    $dir = $plugin["directory"];
    $filename = "plugins/$dir/index.during.php";
    if(is_file($filename)){
    	require_once $filename;
    }
    }

     

    I don't know if it is a good method or not, but in index.php this code runs in the middle of the page, it calls index.during.php and executes the script in there. That script is a procedural script that runs how ever it is programmed.

     

    Now I have come to another question... how would you make a plugin for a plugin? For example say I make a "Blog" plugin it has an entire blogging system built. Now lets say to my blog I want to add a poll system so people can vote for something.

     

    Any suggestions on an approach to do that?

  11. In my Netbeans editor, I get this warning, when using a variable that is defined in an included file:

    Variable $name seems to be uninitialized

     

    Anyone know how to make Netbeans see that it is in fact initiated in the file that is being included?

     

    config.php

    <?php
    $temp = new Template();

     

    index.php

    <?php
    /** 
    * @var $temp Template
    */
    require_once "config.php";
    $temp->display("index.tpl");

     

    In my above example, in index.php $temp says Variable $temp seems to be uninitialized and yet it is but in the included file. adding the @var turns on auto complete, in the file for $temp, but the variable still shows it is uninitialized.

     

    So, Anyone know how to turn it on in Netbeans?

  12. I have the 2nd Gen Zune (has the pad on the bottom), and it works great! The only issue I have with Zune is you can not connected it to your car stereo and control it through the stereo like an iPod. If I were to use something connected to my car speaker I would use a phone, unless the new Zunes have Bluetooth.

  13. I am thinking of creating an application that allows for user plugins to extend the functionality of the application. I have written one before, but I am not sure if it is a good way of doing it.

     

    Any suggestions on how one could be created, and best practices for making one?

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.