What objects are available within the various files of a block?

Permalink
I still am having trouble understanding what is what with C5.

A case in point is knowing which objects are available to me from within the edit.php or the controller.php files of a block.

I mean I know some of them but there doesn't seem to be any rhyme or reason to it. It's just that some exist and some don't and one has to go mucking around inside long code files and otherwise be guessing to figure out which one's are around or not.

I am trying to arrive at come clear reference to what is available so that I don't have to guess or otherwise hit or miss some object at random by trying different object names within print_r's to see is an object exists.

For example within my themes header.php file (inside the /themes/custom_theme/elements/ directory)...one can access the method getThemePath() just fine like so...

<link rel="stylesheet" media="screen" type="text/css" href="<?php echo $this->getThemePath() ?>/main.css" />


Try and access that method of whatever $this object is inside the blocks controller.php file and no go.

The $this inside the controller.php file isn't the same $this as found inside the header.php file.

Is there like some sort of $this->get_this_name() LOL to help one figure out what the $this is in a given file?

I hate developing like a blind man hoping that this or that is available.

Isn't there some way to tell for sure?

Carlos

 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Try:
$vars = get_defined_vars();
print_r($vars); //or you could use var_dump($vars)
carlos123 replied on at Permalink Reply
Hi Jordan,

I tried PHP's get_defined_vars() before and it didn't pick up a bunch of stuff that I knew for sure was there that was internal to C5 and how it does things.

In any case Jordan, I've pretty much decided to go back to using my own custom created CMS to build web sites as I got fed up trying to figure out what is what in the source code of Concrete5 but I'll play with your suggestion a bit more when I get the chance Jordan.

Concrete5 is great for an end user that wants nice drag and drop functionality to page elements and who wants an easy to understand interface but for a web developer like me who wants to be able to understand what C5 is doing underneath so that I can modify it to do what I need it to do on a site...it's not so good.

The code is incredibly complex (in many respects unnecessarily so), lacking in useful comments, uses globals here and there that are defined who knows where, and otherwise veers from best practices programming principles that makes it difficult to work with.

I may still submit some blocks I have created to the MarketPlace and create some alternate documentation for C5 at my site... but after I finish this present clients site with C5...I think that will be it for my use of C5 to build client sites.

Thanks for all the help you have given me Jordan. Much appreciated.

Carlos
codingpenguins replied on at Permalink Reply
This is quite simple. If $this is used in a class it is referring to the class. Example of block controllers, using $this is actually referring to the "BlockController" which the file shows that it is extended from on the class define at the top of the file. Which is define in the /concrete/libraries/block_controller (using concrete naming adds a '_' for the next word). Then Blockcontroller extends Controller which you can say $this is actually used from (even though $this could be used to find any methods - the whole Object Oriented extend thing). On the other example of the header.php file this is more like a concrete object (since no class is defined) which is /concrete/libraries/view.php which is from a View object. The best way I do this is just do a grep or findstr search for the methods name and find the parent class, so I know the type of object. It is actually pretty simple, when you start learning about the organization of everything. Also, if there is more then one class that have that method define, just look at the class name and see if it fits what your looking for. Like with getThemePath also appears in block_view, but since the header is per page NOT block, it is good to assume that this is not the parent class. Hopefully all this makes since, let me know if you need me to clear anything up.
carlos123 replied on at Permalink Reply
Thanks codingpenguin. Appreciate the input...though...well...it doesn't help me much in that I use grep continually to try and find out where a class is at already.

For example I recently wanted to get the theme path and use that value inside the edit.php file of a block that would go and pull in the typography.css file from the theme directory (my block is a replacement for the standard Content block and greatly simplifies the interface and produces nicely formatted and readable HTML instead of the gibberish produced by TinyMCE).

While grep did indeed help me find a class that had the getThemePath() method that I could potentially use...the problem was that there were different classes that had that method in different files. Which one to use? No clue.

Furthermore when I tried to use any of the various classes within my controller.php file of the block and to make the theme path value available to the edit.php file by set()ing a variable to the theme path value, it didn't work.

Many times the getThemePath() method of a class didn't even return a value at all within the controller and when it did I could not set a variable to hold that value so as to pass it along to edit.php.

I mean it's likely I did something wrong in their somewhere but my point is that I don't know what that might be (and a forum thread I started to try and find out didn't provide any ready answers either). It's a hit or miss guessing game as to how to do things in the code of Concrete5 more or less.

There is unfortunately no reference (that I am aware of) as to which objects are available within which standard files of a block. By experimentation some objects work in this here file and place in that file and others...well...don't.

Nor are there any standard examples of how to use various objects (their properties and methods) from various places in block files. One has to download various blocks and study their code to get any idea of what is what but even then...again...it's a hit or miss approach where the only thing one knows is that this here block did this and successfully so. Meaning that knowledge of some other object (not used in the downloaded block) that is indeed accessible from block files remains...well...unknown. Such that one must go find another block using a new object to see if what one needs is done somewhere.

A royal pain in the you know what way to learn if you ask me.

Anyway I appreciate your input codingpenguin.

Carlos
codingpenguins replied on at Permalink Reply
That is easy to do
$v = View::getInstance();
return $v->getThemePath();

This gives you the ThemePath like I was saying above. Just grep and as you see in /concrete/libraries/block_view.php uses this same thing. I tested it and it worked for me. Let grep be your friend ; )


EDIT: If you grep you should only look at the files that have the function defined as "public function getThemePath(" NOT the files that have "$this->getThemePath()" - This will do you no good. If you only look at the ones define functions, you should only have 1 to a hand full, no more, unless its crazy simple names, which I do not see concrete using get() or set() or define() alot.

EDIT: also the use of the object depends on how the constructor is. but since like in your case I would just grep at first to see how other files call "getThemePath" and since some had "$v" not "$this" I knew that I could just copy the code over. Eventhough I do agree there is little documentation on the system files, but who really has time. You can if you have it ; ), its open source and it is better documentation than most CMSs. Most people do not need all this documentation, and after tearing it apart I pretty much know the organization of concrete5 and where most things are.
carlos123 replied on at Permalink Reply
Hi codingpenguins.

I tried that and it didn't work for me. Maybe you can take a peek at the other thread I started on that and give me input there?

I've undoubtedly left some of the context of why it did not work for me out here.

You can see the full context of the problem I was having (to which I still have no solution) athttp://www.concrete5.org/community/forums/customizing_c5/how-to-get...

If you don't want to give me input there that's fine codingpenguins. Just saying that your suggested code did not work as stated by you here. At least not in the context of how I was trying to use it.

Thanks.

Carlos
codingpenguins replied on at Permalink Reply
Posted on your other forum for edit.php and add.php in blocks.