Question

My project looks like this:

- root<br>
 - module
     - Application
         - view 
             - application
                 - index
                     - index.phtml
      - ZfcUser
         - view
             - zfc-user
                   - user
                      - login.phtml

(Sorry if isn't readable it's my first post I tried my best)

When I go to (from my web browser) http://site.local/user and I'm authenticated ZfcUser display login.phtml

Now I want to show some information coming from my module application but I don't want to write specific code on login.phtml or even on any ZfcUser controller since I think it isn't a good practice.

The good practice(I guess) should be to have a prepared controller on application where I give some content to the caller.

Can I get that directly from login.phtml?

Sorry for my English. It isn't my main language if you have trouble understanding my problem feel free to reply and asking for more clarification.

I'm looking for the best method to do this to really understand how it have to be done.

Thanks for paying attention to my problem.

Was it helpful?

Solution 2

Here is my solution (The previous one was wrong but I let it for informal/logical purpose about the answers I got)

Instead of going into ZfcUser after login I have route the request to ZfcDataGrid. To do that simply edit the UserController.php on ZfcUser/Controller/ and modify indexAction to looks like:

if (!$this->zfcUserAuthentication()->hasIdentity()) {
        return $this->redirect()->toRoute('zfcuser/login');
    }
return $this->redirect()->toRoute('ZfcDatagrid');

Here we check if we are authenticated, if we are we go to ZfcDataGrid, if not we go to default zfcuser login.

On my Data file I used this: (on ZfcDataGrid Data file provides the content used to render the grid)

    $sm = $this->getServiceLocator();                
    $this->newsTable = $sm->get('Application\Model\News');
    $news = $this->newsTable->fetchAllToArray();

    foreach ($news as $index=>$value) {
        $data[$index] = $value;            
    }                

    return $data;

Then on my .phtml

<div name="zfcuser" style="position:relative; top:10px; left:80%;">
<div style="float:left; padding-right:16px;">
<?php echo $this->gravatar($this->zfcUserIdentity()->getEmail()) ?></div>
<h3><?php echo $this->zfcUserDisplayName() ?>!</h3>
<a href="<?php echo $this->url('zfcuser/logout') ?>">[Sign Out]</a>
<div style="clear:both;"></div>
</div>
<a class="btn btn-primary" href="<?php echo $this->url('ZfcDatagrid') ?>"
<?php echo    $this->translate('cancelback') ?>
role="button"    class="btn" data-toggle="modal">Cancel and back to previous page</a>
<?php
echo '
<h2>Title : ' . $new[0]['title'] . '</h2>'; ?>
<form method="post" action="somepage">
<textarea name="content" style="width:100%">

<?php echo '<p>' . $new[0]['content'] . '</p>
'?></textarea>
</form><a class="btn btn-primary" href="<?php echo 
                        $this->url("news")."save";?>">
<?php echo $this->translate('Validate'); ?>
</a>

So the answer I found it's to use model you need on the other module controller (use Application\Model\NewsModel;) Then on the controller get the data from your model and pass the results to your view. Then on your view show the data.

If someone can tell me if it's the right way to do what I wanted or if needed more explanation feel free to ask.

Thanks again for your help Carlos, I really appreciate it.

Happy new year :D

OTHER TIPS

Thanks for the grammar correction.

Since I got some negative feedbacks (-3) I post my solution here maybe if someone got the same problem it will be helpful...

I have put on the login.phtml something like:

  <?php 
    use Application\Controller\News

    $news = new News();<br>
    $newsContent = $news->getNewsTable();

  ?>

Then I can use the result from this function on my view. It works and I don't think it's a good practice and should be avoided but at least it works.... :|

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top