hackoh / fuel-calendar

Calendar package for FuelPHP
10 stars 2 forks source link

Help Setting UP #3

Closed daniel-rodas closed 10 years ago

daniel-rodas commented 10 years ago

Can you help me setup this calendar please, here is my app controller and my error.

<?php /**

ControllerMycalendar / class Controller_Mycalendar extends Controller_Base { public function action_index() { $this->template->title = "Calendar"; $this->template->contentnode = "*** THIS IS SOME CONTENT NODE YO ***";

        $years = array();

        foreach (range(2013, 2020) as $year)
        {
            $years[] = \Calendar::year($year);
        }

        $this->template->content_cover = View::forge('calendar/year', array('year' => $year), false);
}

}

/*** Error **/

Notice! Fuel\Core\PhpErrorException [ Notice ]: Undefined variable: year

PKGPATH/calendar/views/calendar/year.php @ line 1

0 1

<?php echo $year->year; ?>

2<?php foreach ($year->get_months() as $month): ?> 3 <?php echo $month->month ?>

4 5 <?php foreach ($month->get_weeks() as $week): ?> 6 Backtrace COREPATH/bootstrap.php @ line 98 PKGPATH/calendar/views/calendar/year.php @ line 1 COREPATH/classes/view.php @ line 240 COREPATH/classes/view.php @ line 254 COREPATH/classes/view.php @ line 565 COREPATH/classes/view.php @ line 207 APPPATH/views/layouts/manmadesteak.php @ line 18 COREPATH/classes/view.php @ line 240 COREPATH/classes/view.php @ line 254 COREPATH/classes/view.php @ line 565 COREPATH/classes/view.php @ line 207 DOCROOT/index.php @ line 78

noxify commented 10 years ago

Hi,

it looks like that, the second "year" in "$year->year" is not defined.

Can you check the $year variable in your view with the following code?

<?php var_dump($year); ?>

...

EDIT:

You can also try this code:

foreach (range(2013, 2020) as $year)
        {
            $years[] = \Calendar::year($year);
        }

        $this->template->content_cover = View::forge('calendar/year', array('year' => $years), false);
}

I have replaced: $this->template->content_cover = View::forge('calendar/year', array('year' => $year), false);

with: $this->template->content_cover = View::forge('calendar/year', array('year' => $years), false);

Because $year is only available in the foreach ;) I think this should fix your problem.

daniel-rodas commented 10 years ago

Thanks for the quick response, I replaced the foreach code in Mycalendar controller like you recommended but then I get a second error and here is the var_dump($year); and the new error message;

array(8) { [0]=> object(Calendar\Calendar_Cell_Year)#45 (4) { ["_offset":protected]=> int(0) ["_calenadar_name":protected]=> string(7) "default" ["_params":protected]=> array(2) { ["year"]=> int(2013) ["time"]=> int(1357027200) } ["_data":protected]=> NULL } [1]=> object(Calendar\Calendar_Cell_Year)#46 (4) { ["_offset":protected]=> int(0) ["_calenadar_name":protected]=> string(7) "default" ["_params":protected]=> array(2) { ["year"]=> int(2014) ["time"]=> int(1388563200) } ["_data":protected]=> NULL } [2]=> object(Calendar\Calendar_Cell_Year)#47 (4) { ["_offset":protected]=> int(0) ["_calenadar_name":protected]=> string(7) "default" ["_params":protected]=> array(2) { ["year"]=> int(2015) ["time"]=> int(1420099200) } ["_data":protected]=> NULL } [3]=> object(Calendar\Calendar_Cell_Year)#48 (4) { ["_offset":protected]=> int(0) ["_calenadar_name":protected]=> string(7) "default" ["_params":protected]=> array(2) { ["year"]=> int(2016) ["time"]=> int(1451635200) } ["_data":protected]=> NULL } [4]=> object(Calendar\Calendar_Cell_Year)#49 (4) { ["_offset":protected]=> int(0) ["_calenadar_name":protected]=> string(7) "default" ["_params":protected]=> array(2) { ["year"]=> int(2017) ["time"]=> int(1483257600) } ["_data":protected]=> NULL } [5]=> object(Calendar\Calendar_Cell_Year)#50 (4) { ["_offset":protected]=> int(0) ["_calenadar_name":protected]=> string(7) "default" ["_params":protected]=> array(2) { ["year"]=> int(2018) ["time"]=> int(1514793600) } ["_data":protected]=> NULL } [6]=> object(Calendar\Calendar_Cell_Year)#51 (4) { ["_offset":protected]=> int(0) ["_calenadar_name":protected]=> string(7) "default" ["_params":protected]=> array(2) { ["year"]=> int(2019) ["time"]=> int(1546329600) } ["_data":protected]=> NULL } [7]=> object(Calendar\Calendar_Cell_Year)#52 (4) { ["_offset":protected]=> int(0) ["_calenadar_name":protected]=> string(7) "default" ["_params":protected]=> array(2) { ["year"]=> int(2020) ["time"]=> int(1577865600) } ["_data":protected]=> NULL } }

Notice! Fuel\Core\PhpErrorException [ Notice ]: Trying to get property of non-object

PKGPATH/calendar/views/calendar/year.php @ line 2

0 1<?php // echo '

'; var_dump($year); die; ?>
2

<?php echo $year->year; ?>

3<?php foreach ($year->get_months() as $month): ?> 4

<?php echo $month->month ?>

5 6 <?php foreach ($month->get_weeks() as $week): ?> 7 Backtrace

COREPATH/bootstrap.php @ line 98 PKGPATH/calendar/views/calendar/year.php @ line 2 COREPATH/classes/view.php @ line 240 COREPATH/classes/view.php @ line 254 COREPATH/classes/view.php @ line 565 COREPATH/classes/view.php @ line 207 APPPATH/views/layouts/manmadesteak.php @ line 18 COREPATH/classes/view.php @ line 240 COREPATH/classes/view.php @ line 254 COREPATH/classes/view.php @ line 565 COREPATH/classes/view.php @ line 207 DOCROOT/index.php @ line 78 Prior Contents (show)

FuelPHP is released under the MIT license.

daniel-rodas commented 10 years ago

sorry for the crazy formatting.

noxify commented 10 years ago

Hi,

If you add "```" before and after your code, you will get a better formatting ;) More information about this, can you find here: https://help.github.com/articles/github-flavored-markdown

Okay.. back to topic. I don't installed the package, but i think there is a problem in your script.

As I can see you have the following controller:

<?php
class Controller_Mycalendar extends Controller_Base
{
    public function action_index()
    {
    $this->template->title = "Calendar";
    $this->template->content_node = "******* THIS IS SOME CONTENT NODE YO *******";

        $years = array();

        foreach (range(2013, 2020) as $year)
        {
            $years[] = \Calendar::year($year);
        }

        $this->template->content_cover = View::forge('calendar/year', array('year' => $years), false);
    }
}

And your view looks like:

<?php echo $year->year; ?>

<?php foreach ($year->get_months() as $month): ?>

    <?php echo $month->month ?>

    <?php foreach ($month->get_weeks() as $week): ?>
        <?php echo $month->month ?>
    <?php endforeach; ?>
<?php endforeach; ?>

I have checked the documentation from the package and I think there are now only one or two issues, which we have to fix.

First issue: In the controller we the currently:

$this->template->content_cover = View::forge('calendar/year', array('year' => $years), false);

But we should change it to: (add a "s" to year)

$this->template->content_cover = View::forge('calendar/year', array('years' => $years), false);

The rest from the controller looks like the code in the documentation.

Soo.. now the second issue:

The the current view, we we to use the following code (same as in the documentation)

<?php foreach ($years as $year): ?>
<h1><?php echo $year->year; ?></h1>
    <?php foreach ($year->get_months() as $month): ?>
    <h2><?php echo $month->month ?></h2>
    <table border="1">
        <?php foreach ($month->get_weeks() as $week): ?>
            <tr>
            <?php foreach ($week as $day): ?>
                <td style="background-color: <?php echo $day->month == $month->month ? ($day->is_holiday() ? 'pink' : 'white') : 'gray' ?>"><?php echo $day->format('j') ?></td>
            <?php endforeach; ?>
            </tr>
        <?php endforeach; ?>
    </table>
    <?php endforeach; ?>
<?php endforeach ?>

The difference between your code and the documentation code is the first foreach.

I think with this changes it should work.

Hopd this helps.

daniel-rodas commented 10 years ago

Cool yeah it's working now, just have to work on the formatting.

hackoh commented 10 years ago

@noxify Thanks for your good advices :smile:

@daniel-rodas If you want to implement more simply, you can try following code in your view file.


<?php foreach (range(2013, 2020) as $year) : ?>
<?php echo Request::forge('calendar/year/'.$year)->execute() ?>
<?php endforeach; ?>

This code means this package allows you to build the calendar via HMVC. And you can override the view by your app views. For example, you can copy the view file to app/views/calendar/year.php from packages/calendar/views/calendar/year.php And change as you like for example following.

<p class="year"><?php echo $year->year; ?></p>
<?php foreach ($year->get_months() as $month): ?>
<p class="month"><?php echo $month->month ?></p>
<table class="table table-rounded table-bordered">
        <?php foreach ($month->get_weeks() as $week): ?>
                <tr>
                <?php foreach ($week as $day): ?>
                        <td style="background-color: <?php echo $day->month == $month->month ? ($day->is_holiday() ? 'pink' : 'white') : 'gray' ?>"><span class="label"><?php echo $day->format('j') ?></span><p class="well"><?php echo $day->get_data() ?></p></td>
                <?php endforeach; ?>
                </tr>
        <?php endforeach; ?>
</table>
<?php endforeach; ?>
hackoh commented 10 years ago

The view file in app is stronger than the package's.

hackoh commented 10 years ago

@daniel-rodas

Could I close this issue?

daniel-rodas commented 10 years ago

Thanks man, yeah you guys have been very helpful.