How does one know what objects are available inside the controller.php of a block????????

Permalink
I've asked this before and I still don't know.

Anybody?

This is absolutely NUTS!!!!

NUTS.

I mean why doesn't the following code work?? Beats me.

public function add() {
      $bv = new BlockView();
      $bv->setBlockObject($this->getBlockObject());
      $blockURL = $bv->getBlockURL();
      exit;
   }


I get the error....

"Fatal error: Call to a member function getPackageID() on a non-object...blah, blah, blah".

I am trying to get the block path during an add operation. How hard can it be to get that??

Does anybody know how to tell what objects and classes, methods and properties are available from within the controller.php file of a block??????????????

I'm sick and tired of having to try bits and pieces of code from off this forum hoping they work where sometimes they do and sometimes they don't. Ine meene miney mo. C5 loves me. C5 loves me not.

Might as well code by lymeric than try and figure out how C5 is doing things. That's how bad this hit or miss programming, sometimes it works and sometimes it doesn't and for who knows why not, is.

Carlos

 
12345j replied on at Permalink Reply
12345j
what are you trying to do with the url?
carlos123 replied on at Permalink Reply
I am trying to load a CSS file for add and edit through the edit.php file.

As in..

<link rel="stylesheet" type="text/css" href="/blocks/cgc_image_with_zoom/addedit.css" />


In other words I want to replace the "/blocks/cgc_image_with_zoom/" with a variable that will hold the name of the block.

addedit.css is a CSS file that holds CSS that is to be applied only to adds or edits of a block.

Carlos

PS. I've already discussed how to include CSS for a block during an add or edit operation with others 12345j so, though I am open to hearing otherwise, I'd just as soon not discuss that issue again in this thread if you feel inclined to question why I am doing this. Thanks.
Mnkras replied on at Permalink Reply
Mnkras
Whats the full error, that may be a bug with c5
carlos123 replied on at Permalink Reply
Hi Mnkras,

I'll uploaded an image of the error tomorrow Mnkras (as I am not at my computer tonight).

It's an error that I can't copy and paste for some reason. When I run the mouse over it to highlight it...well...I can't highlight anything. It's an xdebug screen.

Anyway I'll upload the image tomorrow.

Carlos
Mnkras replied on at Permalink Reply
Mnkras
view the source of the page, its easier to copy that way
carlos123 replied on at Permalink Reply
Good tip Mnkras!

Thanks.

Carlos
carlos123 replied on at Permalink Reply 2 Attachments
Hi Mnkras,

Viewing source didn't do any good it turns out. There was no error inside the source code that showed up.

But an error occurred nevertheless.

Attached are two images. It took two to capture the error since the little window that showed up was only as wide as my block which did not allow enough space to view the whole error page.

Anyway...all I did, and I mean all that I did is add the following to the add function inside the controller of the block...

$bv = new BlockView();
      $bv->setBlockObject($this->getBlockObject());
      $blockURL = $bv->getBlockURL();


Cleared the browser cache. Didn't do any good.

Reloaded the page to which I was trying to add a block. Didn't do any good.

The error remains.

Here is the full add() function inside the controller.php file of the block.

public function add() {
      $bv = new BlockView();
      $bv->setBlockObject($this->getBlockObject());
      $blockURL = $bv->getBlockURL();
      //Defaults for new blocks
      $this->set('fIDLarge', 0);
      $this->set('thumbWidth', 500);
      $this->set('thumbHeight', 0);
   }


Like I said the only change made to the block code, from a working version, to a broken, error one is that I added the lines indicated above to the add() function.

Your guess is as good as mine as far as what is wrong and why this code is not working.

I've given up trying to get the block url and have just hard coded it into edit.php to get around this error.

For that matter I've given up on C5 as a viable and long term CMS to use. Too many such problems.

Having said that...I would like to know what is causing this error if you don't mind sharing whatever you find out about this with me.

Thanks.

Carlos
olliephillips replied on at Permalink Reply
olliephillips
I've probably missed something here but this code would seem to return the path to the block itself. Since you're in the controller you should be able to use this, you'll know the blocks handle.

Too late to test for you before posting I'm afraid, but I'm sure I've done something like this before.

$myBlock = Block::getByName($blockhandle);
$myBlockPath = $myBlock->getBlockPath();
carlos123 replied on at Permalink Reply
Nope.

Doesn't work olliephillips.

Causes the same error as mentioned above in this thread.

Maybe I am doing something wrong in the block somewhere though I can't for the life of me figure out what that might be since if I take out your suggested code or the code that I indicated above the block works just fine.

Carlos
olliephillips replied on at Permalink Reply
olliephillips
I've had an issue like this before, trying to call something statically didn't work when I thought it should be available, instantiating a new object did.

Do this - it works, I've just tested it.

public function add() {
  $myBlock = new Block();
  $myBlockName = $myBlock->getByName('auto_nav'); //autonav example
  $myBlockPath = $myBlockName->getBlockPath();
  //echo $myBlockPath;
  //die();
}
carlos123 replied on at Permalink Reply
Well...I'll be...

Your code did work. I tested it in two different browsers. No problem at all.

Why your code worked and the previous code didn't is beyond me. Seems like something is screwy with C5 in this case though I still am open to hearing about anything I could be doing wrong on my block.

If anyone wants a copy of the block I'd be happy to zip it up and post it as long as you are willing to give me feedback on what may be wrong in it (if anything).

It's a very customized block for my client so it's not one you can readily use otherwise than on his web site (though you could massage it and change it a bit and make it more generic I suppose but getting feedback on this problem is more important to me than the risk that someone will rip off my block).

Still...I won't give it out to just anybody for the asking but if you've been around here a while and want to play with the block in relation to this problem...by all means I will get it to you.

Carlos
carlos123 replied on at Permalink Reply
Hi Ollie,

To be complete as to the subject of this thread...your code did indeed work with respect to not producing the error I described above but, it did not work with respect to actually giving me what I wanted Ollie.

Namely the path to the block directory. What it gives me is the path to the /blocks/ directory.

In other words if my block is inside /blocks/cgc_image_with_zoom/

What I need to get is the "/blocks/cgc_image_with_zoom/"

Your code only returns "/blocks/" which doesn't really do me any good as I still have to hard code the "/cgc_image_with_zoom/" into my code.

Does anyone (or you Ollie) here know how I might be able to get the path to the block directory? I don't mean the block directory as in "/blocks" I mean the block directory where a custom block resides as in "/blocks/<name of the custom block directory>"?

Carlos

PS. The "/" at the end of my paths above is not actually returned. I added that to more clearly distinguish that I was looking for and referring to directories.